-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_claude_code.sh
More file actions
173 lines (140 loc) · 5.23 KB
/
Copy pathinstall_claude_code.sh
File metadata and controls
173 lines (140 loc) · 5.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/bin/bash
# Claude Code Installation Script for Linux
# Supports Fedora, Ubuntu/Debian, and other Linux distributions
# This script will set up Node.js, npm, and install Claude Code
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Function to check if a command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Function to detect Linux distribution
detect_linux_distro() {
if [ -f /etc/os-release ]; then
. /etc/os-release
echo "$ID"
elif [ -f /etc/redhat-release ]; then
echo "rhel"
elif [ -f /etc/debian_version ]; then
echo "debian"
else
echo "unknown"
fi
}
# Function to install system dependencies
install_dependencies() {
local distro=$(detect_linux_distro)
echo -e "${YELLOW}Installing system dependencies...${NC}"
case $distro in
"fedora" | "rhel" | "centos")
sudo dnf install -y curl git nodejs npm
;;
"ubuntu" | "debian" | "linuxmint" | "pop" | "elementary" | "kali" | "parrot")
sudo apt-get update
sudo apt-get install -y curl git nodejs npm
;;
"arch" | "manjaro" | "endeavouros")
sudo pacman -S --noconfirm curl git nodejs npm
;;
"opensuse-tumbleweed" | "opensuse-leap" | "suse")
sudo zypper install -y curl git nodejs npm
;;
*)
echo -e "${YELLOW}Unsupported distribution. Trying to install with generic package manager...${NC}"
if command_exists dnf; then
sudo dnf install -y curl git nodejs npm
elif command_exists apt-get; then
sudo apt-get update
sudo apt-get install -y curl git nodejs npm
elif command_exists pacman; then
sudo pacman -S --noconfirm curl git nodejs npm
elif command_exists zypper; then
sudo zypper install -y curl git nodejs npm
else
echo -e "${RED}Could not determine package manager. Please install Node.js and npm manually.${NC}"
exit 1
fi
;;
esac
}
# Function to install NVM (Node Version Manager)
install_nvm() {
echo -e "${YELLOW}Installing NVM (Node Version Manager)...${NC}"
if [ ! -d "$HOME/.nvm" ]; then
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
# Load NVM
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
echo -e "${GREEN}NVM installed successfully.${NC}"
else
echo -e "${YELLOW}NVM is already installed.${NC}"
# Load NVM if not already loaded
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
fi
# Install the latest LTS version of Node.js
nvm install --lts
nvm use --lts
}
# Function to set up npm global directory
setup_npm_global() {
echo -e "${YELLOW}Setting up npm global directory...${NC}"
# Create a directory for global npm packages
mkdir -p "$HOME/.npm-global"
# Configure npm to use the new directory
npm config set prefix "$HOME/.npm-global"
# Add to PATH if not already present
if ! grep -q "\.npm-global" "$HOME/.bashrc"; then
echo 'export PATH=~/.npm-global/bin:$PATH' >> "$HOME/.bashrc"
echo 'export NPM_CONFIG_PREFIX=~/.npm-global' >> "$HOME/.bashrc"
fi
# Update current shell
export PATH="$HOME/.npm-global/bin:$PATH"
export NPM_CONFIG_PREFIX="$HOME/.npm-global"
echo -e "${GREEN}npm global directory set up at $HOME/.npm-global${NC}"
}
# Function to install Claude Code
install_claude_code() {
echo -e "${YELLOW}Installing Claude Code...${NC}"
# Install Claude Code globally
npm install -g @anthropic-ai/claude-code
echo -e "${GREEN}Claude Code installed successfully!${NC}"
}
# Function to verify installation
verify_installation() {
echo -e "\n${YELLOW}Verifying installation...${NC}"
echo -e "\n${GREEN}Installation complete!${NC}"
echo -e "\nTo start using Claude Code, you may need to run:"
echo -e "source ~/.bashrc # or open a new terminal"
echo -e "claude-code --help # to see available commands"
echo -e "\n${YELLOW}Note:${NC} Make sure to set your Anthropic API key as an environment variable:"
echo -e "export ANTHROPIC_API_KEY='your-api-key-here'"
echo -e "Or add it to your ~/.bashrc file for persistence."
}
# Main installation process
main() {
echo -e "${GREEN}Starting Claude Code installation...${NC}"
# Check if running as root
if [ "$(id -u)" -eq 0 ]; then
echo -e "${RED}This script should not be run as root. Please run as a normal user.${NC}"
exit 1
fi
# Install system dependencies
install_dependencies
# Install NVM and Node.js
install_nvm
# Set up npm global directory
setup_npm_global
# Install Claude Code
install_claude_code
# Verify installation
verify_installation
}
# Run the installation
main "$@"