Installing Claude Code (Anthropic's official CLI tool) on a remote VPS

Installing Claude Code (Anthropic’s official CLI tool) on a remote VPS requires a Node.js environment. Because a VPS is usually a “headless” environment (no graphical web browser), the installation and authentication process has a few specific steps.

Here is the step-by-step guide to installing the latest version of Claude Code on a remote Linux VPS (Ubuntu/Debian/CentOS).

Step 1: SSH into your VPS

Open your local terminal and connect to your VPS:

ssh username@your_vps_ip_address

Step 2: Install Node.js (Prerequisite)

Claude Code is distributed as an npm package and requires a modern version of Node.js (v18 or higher).

The best way to install Node.js on a VPS without running into global permission issues is by using NVM (Node Version Manager).

  1. Install NVM:
    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
    
  2. Reload your shell configuration (so the nvm command is recognized):
    source ~/.bashrc   # or ~/.zshrc if you use Zsh
    
  3. Install the latest LTS (Long Term Support) version of Node.js:
    nvm install --lts
    
  4. Verify the installation:
    node -v
    npm -v
    

Step 3: Install Claude Code

Now that npm is installed, you can install the official Claude Code package globally. This command will always fetch the latest version.

npm install -g @anthropic-ai/claude-code

Step 4: Authenticate on a Headless VPS

To use Claude Code, you need to authenticate. Since you are on a remote server without a web browser, you have two options:

Option A: Use Device Authorization (Recommended)

When you run the login command, Claude Code will generate a link for you to open on your local computer.

  1. Run the login command:
    claude login
    
  2. The terminal will output a URL and a verification code.
  3. Copy the URL, open it in the web browser on your local computer, log in to your Anthropic account, and enter the code.
  4. Your VPS terminal will automatically detect the successful login.

Option B: Use an API Key Environment Variable

If you prefer not to use the web login, or if you are automating this VPS, you can use an API key from the Anthropic Console.

  1. Generate an API key in the Anthropic Console.
  2. Add it to your VPS environment variables by editing your profile:
    echo 'export ANTHROPIC_API_KEY="your-api-key-here"' >> ~/.bashrc
    source ~/.bashrc
    

Step 5: Run Claude Code

Navigate to the directory containing your code on the VPS, and simply type:

claude

This will launch the interactive Claude environment directly in your SSH session, allowing it to read your files, execute commands, and help you code.


Pro-Tips for using Claude Code on a VPS

  • Use tmux or screen: Because you are on a remote connection, if your SSH session drops, Claude Code will close. Start a tmux session before running claude so you can reconnect if your internet blips out.
    tmux            # Starts a persistent session
    claude          # Run claude
    # To detach, press: Ctrl+b, then d
    # To reattach later: tmux attach
    
  • How to update to the latest version later: Whenever Anthropic pushes an update, simply run:
    npm update -g @anthropic-ai/claude-code