Claude Code is Anthropic’s terminal CLI for its Claude models: Fable 5 and Claude Opus 4.8 for the heaviest reasoning, Sonnet 5 with its million-token context, and Haiku 4.5 for speed. Which one runs by default depends on your plan. Same models that power Claude.ai, but with full repository awareness, hooks, sub-agents, and MCP servers that the chat window never gives you. The install story on Ubuntu changed recently: Claude Code now ships as a self-contained native binary, so the fastest path is a single curl command with no Node.js in the picture at all.
This guide installs Claude Code on a fresh Ubuntu 26.04 server three ways (the native installer, the signed apt repository, and npm), wires up OAuth or API-key auth, writes a sane settings file, and attaches an MCP server so the CLI can read live data from your stack. Every command was run end to end on a clean box.
Re-tested in July 2026 on a fresh Ubuntu 26.04 (Resolute Raccoon) server with the native Claude Code 2.1.217 build. The same one-line installer works on Ubuntu 24.04 and 22.04.
Prerequisites
- Ubuntu 26.04 LTS (or 24.04 / 22.04) with a regular user that has sudo, and at least 4 GB RAM
- A paid Claude plan (Pro, Max, Team, or Enterprise) or a Console API key with billing. The free Claude.ai plan does not include Claude Code access
- Outbound HTTPS to
claude.aiandapi.anthropic.com - Optional: a project directory you want Claude to work against
Step 1: Install Claude Code with the native installer
Anthropic’s recommended method is the native install script. It drops a standalone binary under ~/.local/share/claude, links it to ~/.local/bin/claude, and keeps itself updated in the background. No Node.js, no npm, no global package. Pull and run it in one line:
curl -fsSL https://claude.ai/install.sh | bash
The script prints a success banner with the installed version and the launcher location. If it warns that ~/.local/bin is not on your PATH, add it so the shell can find the claude command:
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
Confirm the binary is callable and healthy. The claude doctor command is a read-only diagnostic, so it runs before you have signed in:
claude --version
claude doctor
A working install reports the version and a clean bill of health, with the install method shown as native:
2.1.217 (Claude Code)
Running: native (2.1.217)
Config install method: native
Search: OK (bundled)
Auto-updates: enabled
Auto-update channel: latest
No installation issues found.
The capture below runs the whole chain on a clean 26.04 box, from the install script to the claude doctor checkup:

From here the CLI is callable as claude from any directory, and the background updater keeps it current. If you would rather manage versions through your package manager, Step 2 covers the apt and npm routes instead.
Step 2: Alternative install methods (apt and npm)
The native installer suits most people, but two other paths matter on servers and in fleets where updates flow through the system package manager.
Signed apt repository
Anthropic publishes a GPG-signed apt repository, which is the cleanest option when you manage packages centrally. Add the keyring and the repo, then install:
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 -y claude-code
Before trusting the key, verify its fingerprint matches the one Anthropic publishes:
gpg --show-keys /etc/apt/keyrings/claude-code.asc
The fingerprint should read 31DD DE24 DDFA B679 F42D 7BD2 BAA9 29FF 1A7E CACE. The stable channel above trails the newest release by roughly a week and skips builds with major regressions; swap stable for latest in both the URL and the suite name to ride the tip. apt installs do not auto-update, so you pick up new versions with the usual sudo apt update && sudo apt upgrade claude-code.
npm (for existing Node setups)
If you already live in a Node toolchain, the CLI is still on the public npm registry as @anthropic-ai/claude-code. It needs Node.js 22 or newer, and it simply pulls the same native binary through a per-platform optional dependency. One thing to get right: install it without sudo. Anthropic explicitly advises against sudo npm install -g because it causes permission and security headaches:
npm install -g @anthropic-ai/claude-code
claude --version
If npm complains that the global directory is not writable, set an unprivileged prefix rather than reaching for sudo (covered in the errors section). To upgrade an npm install later, run npm install -g @anthropic-ai/claude-code@latest, not npm update -g, which respects the original semver range and can leave you behind.
Step 3: Pick an auth path
Claude Code accepts four auth backends. Pick the one that matches your billing:
| Backend | Best for | Setup |
|---|---|---|
| Anthropic account (OAuth) | Pro / Max / Team subscribers, individuals | Browser flow via claude auth login |
| API key | console.anthropic.com pay-per-token, CI runners | ANTHROPIC_API_KEY env var |
| Amazon Bedrock | AWS-hosted Claude billing | CLAUDE_CODE_USE_BEDROCK=1 + AWS creds |
| Google Vertex AI | GCP-hosted Claude billing | CLAUDE_CODE_USE_VERTEX=1 + ADC |
Path A: OAuth login (Anthropic account)
Sign in once with the auth command. It prints a URL and a one-time code:
claude auth login
Open the URL in any browser, sign in to your Anthropic account, paste the code back into the terminal, and Claude Code stores a refresh token under ~/.claude. Every later launch reuses that token silently. Check the current state any time with claude auth status.
Path B: API key (best for servers)
For headless servers and CI runners that should never pop a browser, generate a key at console.anthropic.com/settings/keys and export it:
echo 'export ANTHROPIC_API_KEY="your-anthropic-api-key-here"' >> ~/.bashrc
source ~/.bashrc
claude --print "say hello in one sentence"
The --print flag (alias -p) runs the CLI non-interactively and dumps the model’s reply to stdout. It is the quickest way to confirm auth works, and the building block for scripting Claude into pipelines. The first time Claude Code sees the key it asks you to approve it once, so run claude interactively a single time to accept that prompt before you script the --print calls unattended.
Step 4: First interactive session
The interactive REPL is where Claude Code earns its keep. Open it inside a project directory:
cd ~/projects/my-app
claude
The CLI prints its prompt, reads any CLAUDE.md in the current directory or its parents, and waits. A good first turn:
> What does this repo do? Walk me through the main entry points.
Claude reads your README, the project manifest (package.json, pyproject.toml, Cargo.toml, whatever fits), and the file tree, then answers in your terminal. From there you can have it write features, fix bugs, run commands, and edit files. Recent Claude Code defaults to Manual permission mode, so it pauses and asks before it runs a tool or touches a file the first time, which keeps an agent honest on a real machine.
Type /help to list the slash commands (skills, plugins, sessions). Type /model to switch models. The default depends on your plan: Sonnet 5, with its million-token context, on Pro, Team, and Enterprise seats, or Opus 4.8 on Max and API or Console billing. Reach for Fable 5 or Opus 4.8 on the hardest, longest tasks, and Haiku 4.5 when you want speed and a smaller bill. Press Ctrl+C twice to exit.
Step 5: settings.json and CLAUDE.md
Two files turn Claude Code from a chat box into a configurable agent. ~/.claude/settings.json holds global preferences (default model, permissions, hooks, MCP servers). CLAUDE.md holds project-specific instructions and lives at any level of your repo. Create the settings file:
mkdir -p ~/.claude
vim ~/.claude/settings.json
Paste a configuration that pins the model and draws a clear line around what the agent may run:
{
"model": "claude-sonnet-5",
"permissions": {
"allow": [
"Bash(git:*)",
"Bash(npm:*)",
"Bash(pytest:*)",
"Read",
"Edit",
"Write"
],
"deny": [
"Bash(rm -rf:*)"
]
}
}
The permissions block is the safety net. allow lists tool patterns that skip the prompt; deny lists patterns the agent refuses even if you approve them at runtime. These are prefix matches, so Bash(rm -rf:*) catches rm -rf but not rm -fr or a wrapper. Treat the block as a guardrail, not a full sandbox. Lock the file down because it can hold tokens for hooks and MCP servers:
chmod 600 ~/.claude/settings.json
Now give a project its own rules. Drop a CLAUDE.md at the repo root:
vim CLAUDE.md
Write the conventions you want honoured on every turn:
# Project context
Stack: FastAPI + Postgres + Redis behind Caddy.
Run tests with pytest -x. Lint with ruff check .
Keep changes under 200 lines per PR. Prefer dataclasses over dicts.
Claude reads this on session start, follows the conventions, and keeps them in context across multi-turn work. The Claude Code cheat sheet covers the full slash-command and flag surface, the sub-agents guide shows how to fan work out, and the routines guide wires scheduled agent runs.
Step 6: Add an MCP server
MCP (Model Context Protocol) servers let Claude pull live data from your stack: read a database, hit an API, browse a Notion workspace. The claude mcp add syntax takes a name, then the command to launch the server after a -- separator. The filesystem server is the simplest example:
claude mcp add filesystem -- npx -y @modelcontextprotocol/server-filesystem $HOME/projects
claude mcp list
The next interactive session can read and search any file under ~/projects through that server. Drop it again later with claude mcp remove filesystem. For production, swap the filesystem example for the Postgres MCP, the GitHub MCP, or your own. The MCP servers setup guide walks the useful ones, the GitHub Actions guide shows the same pattern in CI, and the Kubernetes integration wires Claude into kubectl.
Step 7: Useful command flags
The CLI surface is large. The flags worth knowing on day one:
| Flag | What it does |
|---|---|
-p, --print | Non-interactive: print Claude’s reply and exit |
-c, --continue | Resume the most recent conversation in this directory |
--add-dir DIR | Allow tool access to additional directories |
--model opus | Override the model for this session (alias: opus, sonnet, haiku, fable) |
--permission-mode manual | Set the permission mode (manual, acceptEdits, auto, bypassPermissions) |
--dangerously-skip-permissions | Skip every permission prompt; sandbox-only |
--mcp-config PATH | Load extra MCP servers from a JSON file |
--bare | Minimal mode: skip hooks, plugins, auto-memory (CI-friendly) |
Combine them. A nightly cron that has Claude scan a repo and draft a changelog, cheaply, on the API key:
cd ~/projects/site && \
claude --bare --model haiku \
--print "review the diff from the last 7 days and write a CHANGELOG entry"
Common errors and what they mean
Error: EACCES: permission denied, mkdir '/usr/lib/node_modules/...'
You ran the npm install against a global directory your user cannot write to. Do not fix it with sudo; Anthropic warns against that for the npm method. The clean way out is the native installer from Step 1, or an unprivileged npm prefix:
mkdir -p ~/.npm-global
npm config set prefix ~/.npm-global
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
npm install -g @anthropic-ai/claude-code
Error: Authentication failed: invalid_grant
The OAuth refresh token expired or got rotated. Force a fresh login:
claude auth logout
claude auth login
On the API-key path instead, confirm the key is exported and matches the prefix in the console with echo $ANTHROPIC_API_KEY | head -c 20.
Error: MCP server failed to start
The command in the MCP definition could not launch, usually a missing package or a typo after the --. Run the same command in your shell to see the real error, then re-add it:
claude mcp remove filesystem
claude mcp add filesystem -- npx -y @modelcontextprotocol/server-filesystem $HOME/projects
Error: Tool 'Bash' is not allowed
The permissions block in settings.json did not include the pattern Claude is trying to run. Add a specific pattern such as Bash(git status:*) or a broader Bash(git:*), then exit and re-enter the REPL to reload the file.
Update and uninstall
A native install updates itself in the background, but you can force it now:
claude update
claude --version
apt installs update with sudo apt update && sudo apt upgrade claude-code; npm installs with npm install -g @anthropic-ai/claude-code@latest. To remove a native install completely, delete the binary, the version store, and your config:
rm -f ~/.local/bin/claude
rm -rf ~/.local/share/claude
rm -rf ~/.claude ~/.claude.json
An apt install comes off with sudo apt remove claude-code plus removing the repo list and keyring; an npm install with npm uninstall -g @anthropic-ai/claude-code. Deleting ~/.claude wipes settings, allowed tools, MCP definitions, and session history, so skip that last line if you plan to reinstall.
For the model behind the default, the Claude Sonnet 5 release notes cover its reasoning and the million-token context. The token-reduction guide shows the patterns that cut your monthly bill, and the hooks guide automates checks around every session. That is the full path: Claude Code installed as a native binary, auth wired, a settings.json with sane permissions, a project CLAUDE.md, and an MCP server attached. Every session now knows your stack, your conventions, and the data sources you chose to expose.