Skip to content

Instantly share code, notes, and snippets.

@gregpriday
Last active October 12, 2025 16:30
Show Gist options
  • Select an option

  • Save gregpriday/b86139e9428dd8f18edcb931659047b3 to your computer and use it in GitHub Desktop.

Select an option

Save gregpriday/b86139e9428dd8f18edcb931659047b3 to your computer and use it in GitHub Desktop.
Install Claude Code
#!/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