This guide walks through installing Claude Code on a headless Ubuntu server, the kind of machine you reach over SSH with no desktop and no browser. Because there is no browser to complete a login flow, you authenticate with an Anthropic API key instead. Ubuntu 26.04 works fine here, and so does anything from Ubuntu 20.04 onward, which is the range Claude Code supports.
Before you start
You need three things: an Ubuntu server (20.04 or newer) you can reach over SSH, an Anthropic Console account with credits or a Pro, Max, or Team plan, and a normal user account with sudo rather than root. The free claude.ai tier does not cover Claude Code, so a Console account with billing is required.
Step 1: Install Claude Code
The native installer is the recommended route. It does not require Node.js:
curl -fsSL https://claude.ai/install.sh | bashThe binary lands in ~/.local/bin/claude. If your current shell does not pick it up right away, reload your profile and check the version:
source ~/.bashrc
claude --versionYou should see something like 2.x.x (Claude Code). If anything looks off, claude doctor runs read-only diagnostics and is a safe first check.
Step 2: Fix the PATH if Claude is not found
A common result right after install is:
claude --version
# claude: command not found
This means ~/.local/bin is not on your PATH in the current shell yet. First confirm the binary is actually there by calling it directly:
~/.local/bin/claude --versionIf that prints a version, add the directory to your PATH permanently and reload:
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
claude --versionIf the full path also reports “no such file”, the installer did not finish. Check what landed:
ls -la ~/.local/bin ~/.local/share/claude 2>&1If those are empty, rerun the installer and watch the output for an error. A bare Ubuntu image sometimes ships without curl, so install it first if needed:
sudo apt install -y curl
curl -fsSL https://claude.ai/install.sh | bashStep 3: Set your API key
Create a key in the Anthropic Console at platform.claude.com, under API Keys. Add it to your shell profile so it survives logouts:
echo 'export ANTHROPIC_API_KEY="sk-ant-..."' >> ~/.bashrc
source ~/.bashrcWith that environment variable set, Claude Code prompts you once to approve the key instead of opening a browser, which is exactly what you want on a headless machine. Remember that the key has to belong to a Console account with credits, or to a Pro, Max, or Team plan.
Step 4: Start your first project
Create a working directory, initialize git, and start Claude Code:
mkdir ~/myapp && cd ~/myapp
git init
claudeOn first run, approve the key when asked. Then run /init inside the session to generate a starter CLAUDE.md file, where you describe the app, your stack, and your conventions so the agent has context to work from.
Two VPS-specific tips
Avoid running as root if you can. Create a normal user with sudo instead. Claude Code will warn you when it runs as root, and it is safer in general because the agent runs shell commands on your behalf.
Run Claude Code inside tmux or screen. A long task should not die because your SSH connection dropped. A persistent session lets you reconnect and pick up where you left off.
Wrapping up
That is the full path on a headless server: install with the native installer, put ~/.local/bin on your PATH, authenticate with an API key, and start your first project inside tmux as a non-root user. Once it is running, the next step is a solid CLAUDE.md and a clear first prompt describing what you are building.