Claude Code CLI on Ubuntu: Install and Run It on a Server

Claude Code CLI on Ubuntu: Install and Run It on a Server
Installing Claude Code CLI on Ubuntu takes just one command, it does not require Node.js and stays up to date on its own. This guide covers that option and also the apt installation method. In addition, it will help you get past issues that can occur during installation on a remote server, like logging in with a terminal only, making sure that a session does not die when you log out and fixing the "command not found" error.
Requirements
Claude Code requires Ubuntu 20.04 or a newer version, a machine with at least 4GB of RAM and an x64 or ARM64 processor (the two most commonly used chip types in servers) and Internet connection, either an Anthropic account or an API key. These are the requirements in Anthropic's setup documentation.
Are you unsure about the version your server runs? You can check your Ubuntu version in just a few seconds.
Installing the Claude Code CLI on Ubuntu with the native installer
Install the CLI with the following command on the server:
curl -fsSL https://claude.ai/install.sh | bash
The script will download a single executable file into ~/.local/bin and configure background updates. Alternatively, you can download the script first with curl -fsSL https://claude.ai/install.sh -o install.sh, examine it and then execute bash install.sh.
In case you want to install a certain version, pass it to the command after bash -s, for instance: curl -fsSL https://claude.ai/install.sh | bash -s 2.1.89.
Installing Claude Code with apt if you prefer keeping everything up to date with the OS packages
If you manage servers with apt, you can apt install Claude Code from Anthropic's repository. It will stay up to date with the other components of the system.
sudo apt install curl gnupg
sudo install -d -m 0755 /etc/apt/keyrings
sudo curl -fsSL https://downloads.claude.ai/keys/claude-code.asc -o /etc/apt/keyrings/claude-code.asc
echo "deb [signed-by=/etc/apt/keyrings/claude-code.asc] https://downloads.claude.ai/claude-code/apt/stable stable main" | sudo tee /etc/apt/sources.list.d/claude-code.list
sudo apt update
sudo apt install claude-code
Updates will come through sudo apt update && sudo apt upgrade claude-code, not through Claude Code itself. Are you new to the tool? Check out our complete apt guide for more info on repositories and updates.
Install the npm package only if you are already using Node.js
The npm package requires Node.js 22 or a newer version:
npm install -g @anthropic-ai/claude-code
Do not use sudo before the command. The official documentation says not to, but many users expect it to be necessary when searching for sudo npm install -g @anthropic-ai/claude-code. If Node.js is not installed yet, check out the guide to install npm on Ubuntu.
Verifying the installation
Make sure that the shell can find the CLI:
claude --version
You should see a version number, for example 2.1.211 (Claude Code). To perform a deeper verification, use the claude doctor command which will print the read-only diagnostics of the installation and your configuration without launching a session.
Logging in on a server with no browser
Execute claude and follow the prompts. Since on a server the browser will not open, press c to copy the login URL, open it on your computer and log in. In case the browser prints the login code instead of redirecting to the app, copy it and enter in the terminal at the "Paste code here if prompted" step. It is common for SSH connections. When the login process finishes successfully, the terminal will show the message "Login successful".
Claude Code saves the login credentials in ~/.claude/.credentials.json with the file permissions 0600 which allows reading only for the user. If you have not secured remote access yet, make sure you check our guide to enabling and securing SSH on Ubuntu.
For unattended servers and scripts or CI jobs you can use one of the two additional ways. Pass the ANTHROPIC_API_KEY environment variable and grant access for the key when asked by Claude Code. Alternatively, execute claude setup-token once which will print a one-year token that you need to export as CLAUDE_CODE_OAUTH_TOKEN. The token requires you to have a Pro, Max, Team or Enterprise plan.
Making the session live after the disconnect
By default, the processes launched in an SSH session will terminate after the disconnection. Use the terminal multiplexer like tmux which will keep them running:
sudo apt install tmux
tmux new -s claude
claude
To detach from tmux, use Ctrl+b followed by d. The session will continue to run on the server. To connect and resume it afterwards, use the following command: tmux attach -t claude.
Updating and uninstalling
The native installs update themselves in the background, and claude update will force the check. In case you manage versions manually on a server, set DISABLE_AUTOUPDATER to 1 in the env section of your settings.json:
{
"env": {
"DISABLE_AUTOUPDATER": "1"
}
}
It will disable the background check, but claude update will still work when you run it manually.
Uninstall the native installation with the following commands:
rm -f ~/.local/bin/claude
rm -rf ~/.local/share/claude
For apt uninstallation, run sudo apt remove claude-code, remove /etc/apt/sources.list.d/claude-code.list and /etc/apt/keyrings/claude-code.asc. To uninstall the npm package, execute npm uninstall -g @anthropic-ai/claude-code. All of these commands will not touch ~/.claude, which contains your settings and session history. To remove it too, make sure that you really want to get rid of your configuration.
Resolving "command not found" issue
If claude --version prints "command not found", the shell cannot find ~/.local/bin. Make sure that the executable is there with the command ls ~/.local/bin/claude, and add this directory to the path:
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
Use ~/.zshrc instead if you are using zsh. In case the installer did not finish, execute free -h and check if the server has 4GB of RAM or more.
Where to run it
Any small VPS will do. The Starter plan on OrbitServers VPS comes with 4 vCPU and 8GB RAM from $39.99/mo (twice as much RAM as required by Claude Code). Login credentials arrive within minutes of payment confirmation.
Get started with Orbit Servers
Low-latency VPS, bare metal, and colocation across the US, EU, and APAC - provisioned instantly and built for performance-critical workloads.
Get startedRelated products
Written by
Julius
Product Manager
Julius is a product-minded builder who cares about making technology simpler and more useful for the people who rely on it. He’s always looking for ways to improve things, one small step at a time, and enjoys turning good ideas into products that work.