Claude Code Series Tutorial 5: How to Install Claude Code?
How to Install Claude Code
Installing Claude Code has no graphical interface with "Next" buttons; everything is done in the command line. If you usually use npm, the whole process takes no more than two minutes.
Prerequisites
Before you start, make sure you have the following:
- Node.js 18 or higher
Check: Runnode -vin the terminal. If the version is below 18, upgrade using nvm, fnm, or directly from nodejs.org. - An Anthropic account
Register athttps://console.anthropic.com. The account will provide an API Key, which is needed after installation. Registration itself is free; actual costs are based on usage. - Network access to Anthropic API endpoints
The default domain isapi.anthropic.com. If your environment requires a proxy, remember to setHTTP_PROXYorHTTPS_PROXYin the terminal.
Installation Method 1: npm Global Install
This is the most common method—install once and use it everywhere.
npm install -g @anthropic-ai/claude-code
After completion, run claude --version. If a version number is printed, installation was successful. After global install, the claude command can be invoked directly from any directory.
If you encounter permission errors (common on macOS for /usr/local/lib), there are two ways to handle it:
- Use
sudoto install (convenient but has security concerns). - Configure npm to use a user directory to avoid sudo:
bash mkdir -p ~/.npm-global npm config set prefix '~/.npm-global'
Then add~/.npm-global/binto yourPATH, and restart the terminal.
Installation Method 2: npx On-Demand
If you don't want to install anything globally, or just want to try it out temporarily, using npx is more straightforward.
npx @anthropic-ai/claude-code
npx will temporarily download the latest package and run it without leaving a global command. It checks for updates on each use, so it stays up-to-date by default. The downside is it's slightly slower (download every time) and not suitable for frequent calls in automated scripts.
Best for: First-time experience, temporary use on someone else's machine, or occasional use.
Verify Normal Startup
After installation, don't rush to authenticate. Run a simple command to see if the tool starts:
claude --help
If help information is displayed, the binary is fine. The next step is to connect your account, which will be covered later.
Both installation methods result in the same tool; subsequent authentication and usage are identical. Choose whichever feels more convenient.
Common Issues
- Node version too low
Version below 18 will directly throw an error, not a warning. Upgrading Node is the simplest solution. - Network timeout
Whether it's downloading packages via npm or connecting to the API later, it may get stuck due to a proxy or firewall. First confirmcurl https://api.anthropic.comworks before proceeding. - Using native cmd on Windows
Although theoretically possible, it's recommended to use Git Bash, WSL2, or Windows Terminal to avoid strange path escaping issues.
评论
暂无已展示的评论。
发表评论(匿名)