Last active
October 12, 2025 16:30
-
-
Save gregpriday/b86139e9428dd8f18edcb931659047b3 to your computer and use it in GitHub Desktop.
Install Claude Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Claude Code Setup Script - Universal Version | |
| # Works in both root and non-root environments | |
| # Automatically detects and handles sudo requirements | |
| set -e # Exit on error | |
| # Detect OS name and version for display | |
| if [ -r /etc/os-release ]; then | |
| . /etc/os-release | |
| OS_NAME="$NAME" | |
| OS_VERSION="$VERSION_ID" | |
| elif command -v lsb_release &> /dev/null; then | |
| OS_NAME=$(lsb_release -si) | |
| OS_VERSION=$(lsb_release -sr) | |
| else | |
| OS_NAME=$(uname -s) | |
| OS_VERSION=$(uname -r) | |
| fi | |
| echo "π Setting up Claude Code on $OS_NAME $OS_VERSION..." | |
| # Function to run commands with or without sudo | |
| run_privileged() { | |
| if [ "$EUID" -eq 0 ]; then | |
| "$@" | |
| else | |
| if command -v sudo &> /dev/null; then | |
| sudo "$@" | |
| else | |
| echo "β Error: This script requires root privileges or sudo" | |
| echo " Please run as root or install sudo first" | |
| exit 1 | |
| fi | |
| fi | |
| } | |
| # Detect if we're running as root | |
| if [ "$EUID" -eq 0 ]; then | |
| SUDO="" | |
| echo "π Running as root, sudo not required" | |
| else | |
| if command -v sudo &> /dev/null; then | |
| SUDO="sudo" | |
| echo "π Running as regular user, will use sudo" | |
| else | |
| echo "β Error: Not running as root and sudo is not available" | |
| echo " Please run as root or install sudo first" | |
| exit 1 | |
| fi | |
| fi | |
| # Check if we're in a subshell that won't persist | |
| if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then | |
| INSTALL_MODE="sourced" | |
| else | |
| INSTALL_MODE="executed" | |
| fi | |
| # Configure Git user | |
| echo -e " | |
| π§ Configuring Git..." | |
| git config --global user.name "Greg Priday" | |
| git config --global user.email "[email protected]" | |
| git config --global github.user "gregpriday" | |
| # Install nvm | |
| echo -e " | |
| π₯ Installing nvm..." | |
| curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash | |
| # Load nvm environment | |
| export NVM_DIR="$HOME/.nvm" | |
| [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" | |
| # Install Node.js 22 | |
| echo -e " | |
| π₯ Installing Node.js 22..." | |
| nvm install 22 | |
| nvm use 22 | |
| nvm alias default 22 | |
| # Install Claude Code | |
| echo -e " | |
| π€ Installing Claude Code..." | |
| npm install -g @anthropic-ai/claude-code | |
| # Install Git LFS | |
| echo -e " | |
| π¦ Installing Git LFS..." | |
| curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | run_privileged bash | |
| run_privileged apt-get update | |
| run_privileged apt-get install -y git-lfs | |
| git lfs install | |
| if command -v git-lfs &> /dev/null; then | |
| echo "β Git LFS installed successfully ($(git lfs version))" | |
| else | |
| echo "β οΈ Warning: Git LFS installation may have failed" | |
| fi | |
| # Install GitHub CLI (gh) | |
| echo -e " | |
| π Installing GitHub CLI..." | |
| curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg -o /tmp/githubcli-archive-keyring.gpg | |
| run_privileged dd if=/tmp/githubcli-archive-keyring.gpg of=/usr/share/keyrings/githubcli-archive-keyring.gpg | |
| run_privileged chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg | |
| echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | run_privileged tee /etc/apt/sources.list.d/github-cli.list > /dev/null | |
| run_privileged apt update | |
| run_privileged apt install -y gh | |
| rm -f /tmp/githubcli-archive-keyring.gpg | |
| if command -v gh &> /dev/null; then | |
| echo "β GitHub CLI installed successfully ($(gh --version | head -n1))" | |
| echo -e " | |
| π Authenticating GitHub CLI..." | |
| gh auth login | |
| else | |
| echo "β οΈ Warning: GitHub CLI installation may have failed" | |
| fi | |
| # ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| # Install Python3 pip and ML/User CLI tools | |
| echo -e " | |
| π Installing Python3 pip..." | |
| run_privileged apt-get install -y python3-pip | |
| echo -e " | |
| π Upgrading pip..." | |
| pip3 install --user --upgrade pip | |
| # Install Weights & Biases CLI | |
| echo -e " | |
| π₯ Installing Weights & Biases CLI..." | |
| pip3 install --user wandb | |
| if command -v wandb &> /dev/null; then | |
| echo "β Weights & Biases CLI installed successfully ($(wandb --version))" | |
| echo -e " | |
| π Authenticating Weights & Biases CLI..." | |
| wandb login | |
| else | |
| echo "β οΈ Warning: Weights & Biases CLI installation may have failed" | |
| fi | |
| # Install HuggingFace Hub CLI | |
| echo -e " | |
| π₯ Installing HuggingFace Hub CLI..." | |
| pip3 install --user huggingface_hub | |
| if command -v huggingface-cli &> /dev/null; then | |
| echo "β HuggingFace Hub CLI installed successfully ($({ huggingface-cli --version; } 2>/dev/null || echo "ver info n/a"))" | |
| echo -e " | |
| π Authenticating HuggingFace Hub CLI..." | |
| huggingface-cli login | |
| else | |
| echo "β οΈ Warning: HuggingFace Hub CLI installation may have failed" | |
| fi | |
| # ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| # Install monitoring tools: htop & nvtop | |
| echo -e " | |
| π Installing htop and nvtop..." | |
| run_privileged apt-get install -y htop cmake libncurses5-dev libncursesw5-dev git | |
| git clone https://github.com/Syllo/nvtop.git /tmp/nvtop | |
| mkdir -p /tmp/nvtop/build && cd /tmp/nvtop/build | |
| cmake .. && make && run_privileged make install | |
| cd ~ && rm -rf /tmp/nvtop | |
| # ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| # Download and install global CLAUDE.md | |
| echo -e " | |
| π Installing global CLAUDE.md for Lambda Labs..." | |
| mkdir -p ~/.claude | |
| curl -fsSL https://gist.githubusercontent.com/gregpriday/eb1289c48e7f75b356b2e57420b72492/raw/e74f47b15a98d2354adbdaf74e386c56817d113e/claude_lambda_labs.md -o ~/.claude/CLAUDE.md | |
| if [ -f ~/.claude/CLAUDE.md ]; then | |
| echo "β Global CLAUDE.md installed successfully at ~/.claude/CLAUDE.md" | |
| else | |
| echo "β οΈ Warning: Failed to download CLAUDE.md" | |
| fi | |
| # ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| # Download and install Claude settings.json | |
| echo -e "\nβοΈ Installing Claude settings.json..." | |
| curl -fsSL https://gist.githubusercontent.com/gregpriday/ae75fa8484ed1bd60c1537b18c59aafa/raw/49f07414c988d1bcfd3b2d968dd1837a5612eb63/claude-settings.json -o ~/.claude/settings.json | |
| if [ -f ~/.claude/settings.json ]; then | |
| echo "β Claude settings.json installed successfully at ~/.claude/settings.json" | |
| else | |
| echo "β οΈ Warning: Failed to download settings.json" | |
| fi | |
| # Add necessary exports to bashrc for future shells | |
| echo -e "\nπ Adding environment setup to ~/.bashrc..." | |
| cat >> ~/.bashrc << 'EOF' | |
| # Claude Code setup | |
| export PATH="$HOME/.local/bin:$PATH" | |
| export NVM_DIR="$HOME/.nvm" | |
| [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" | |
| EOF | |
| # Create completion script for current shell only | |
| cat > ~/.claude-code-setup-complete.sh << 'EOF' | |
| export PATH="$HOME/.local/bin:$PATH" | |
| export NVM_DIR="$HOME/.nvm" | |
| [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" | |
| nvm use 22 >/dev/null 2>&1 | |
| echo "β Claude Code is ready! (Node $(node -v))" | |
| echo "π¦ Git LFS is installed and ready" | |
| echo "π GitHub CLI is installed and ready" | |
| echo "π pip, Weights & Biases CLI, and HuggingFace Hub CLI are installed" | |
| echo "π Global CLAUDE.md loaded from ~/.claude/CLAUDE.md" | |
| echo "Run 'claude --help' to get started" | |
| rm -f ~/.claude-code-setup-complete.sh | |
| EOF | |
| # Final message | |
| echo -e "\nββββββββββββββββββββββββββββββββββββββββ" | |
| echo "β Installation complete!" | |
| echo -e "\nπ― To use in this terminal session, run:" | |
| echo -e " \033[1;32msource ~/.claude-code-setup-complete.sh\033[0m" | |
| echo -e "\nπ Future terminal sessions will be set up automatically!" | |
| echo -e "ββββββββββββββββββββββββββββββββββββββββ" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment