How to Install and Configure an AI Coding CLI Tool: A Practical Claude Code Guide

    Learn how to install and configure Claude Code from scratch. This guide covers system checks, Node.js and Git requirements, proxy settings, npm and script-based installation, PATH and permission issues, network timeouts, and leftover files from older versions. Each major step includes verification commands and troubleshooting guidance.

    How to Install and Configure an AI Coding CLI Tool: A Practical Claude Code Guide

    If you are setting up an AI coding command-line tool locally for the first time, you will typically run into three problems: an unsupported runtime version, insufficient permissions for global installation, or network access issues when connecting to the model service. Using Claude Code as an example, this guide walks through the complete process, from checking your environment to verifying the installation.

    Each step includes a validation command and a corresponding troubleshooting method. You can follow the guide from start to finish or go directly to the troubleshooting sections.

    1. Check Your Environment Before Installation

    1.1 Identify Your Operating System and Terminal

    Windows users can run the commands in this guide with PowerShell or Git Bash. macOS users should open Terminal, while Linux users can use their system terminal emulator.

    The commands in this guide are primarily written for macOS and Linux terminals. Windows-specific differences are noted where necessary.

    1.2 Install Node.js and Verify the Version

    Claude Code runs on Node.js and requires Node.js 18 or later. Download and install the LTS release from the official Node.js website. After installation, run:

    1. node -v
    2. npm -v

    Under normal conditions, node -v returns a version similar to v20.11.0. The major version must be at least 18.

    If the terminal reports command not found, the installation may not have taken effect. Close and reopen the terminal, then try again. If the version is lower than 18, uninstall the older version and install the current LTS release.

    1.3 Install Git

    On Windows, Claude Code relies on Git Bash to execute shell commands. Install Git for Windows, which includes Git Bash.

    On macOS and Linux, run:

    1. git --version

    If the command returns a version number, Git is available and no additional configuration is required.

    1.4 Check Network Access and Configure a Proxy

    Claude Code needs to connect to the model service, so your network must be able to reach the official service. Your account and location must also meet the service requirements described in the official documentation.

    If your organization or local network requires an outbound proxy, use the proxy address provided by your IT department. On macOS or Linux, set the proxy variables as follows, replacing the placeholder with the actual proxy address:

    1. export HTTP_PROXY=http://proxy-address:port
    2. export HTTPS_PROXY=http://proxy-address:port

    In Windows PowerShell, use:

    1. $env:HTTPS_PROXY="http://proxy-address:port"

    npm requires its own proxy configuration:

    1. npm config set proxy http://proxy-address:port
    2. npm config set https-proxy http://proxy-address:port
    3. npm config get https-proxy

    The final command should print the proxy address you configured.

    If you do not need a proxy, remove the settings with:

    1. npm config delete proxy
    2. npm config delete https-proxy

    Proxy usage must comply with applicable laws, organizational policies, and network security requirements. Use it only to access resources you are authorized to use.

    2. Two Installation Methods

    2.1 Install Globally with npm

    This is the recommended method. First, make sure npm can access the configured package registry. Then run:

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

    The -g option installs the package globally, allowing you to run the claude command from any directory.

    After installation, verify the result:

    1. claude --version

    If a version number is displayed, the installation was successful.

    npm downloads the required dependencies automatically. The process may take several minutes depending on your network speed.

    2.2 Use the Official Installation Script

    If you prefer not to rely on npm, or want to use a script-based deployment method, you can use the installation script provided in the official documentation. The script URL may change, so always follow the current official documentation. The following example uses:

    https://claude.ai/install.sh

    Do not pipe a remote script directly into Bash. Download and review it before running:

    1. curl -fsSL https://claude.ai/install.sh -o install.sh
    2. less install.sh
    3. bash install.sh

    During the review, confirm that the domain matches the official documentation and check which files and environment variables the script modifies.

    If the official documentation provides a checksum, calculate the local file’s SHA-256 hash and compare it with the published value:

    1. sha256sum install.sh

    On macOS, use:

    1. shasum -a 256 install.sh

    After the script finishes, verify the installation:

    1. claude --version

    3. Fix Permission and PATH Issues

    3.1 Resolve EACCES Permission Errors

    If the npm global directory belongs to the root user, a regular user may see an error such as:

    1. EACCES: permission denied

    Using sudo is not recommended. Packages installed as root can cause problems when you later update or remove them.

    Instead, move the npm global directory to a location within your user account:

    1. mkdir -p ~/.npm-global
    2. npm config set prefix ~/.npm-global

    Add the following line to ~/.bashrc or ~/.zshrc:

    1. export PATH=~/.npm-global/bin:$PATH

    Then reopen the terminal and verify the npm prefix:

    1. npm config get prefix

    The output should be the directory configured above. You can then reinstall Claude Code:

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

    On Windows, npm’s default global directory is usually located under the user profile, so this error is less common. If it still occurs, check whether an earlier installation command was run with administrator privileges.

    3.2 Resolve command not found

    If the installation succeeds but the terminal cannot find the claude command, the npm global bin directory is probably missing from your PATH.

    First, check the global prefix:

    1. npm config get prefix

    Then locate the command:

    1. which claude

    On Windows, use:

    1. where claude

    If no path is returned, add the bin directory under the npm prefix to your PATH, then reopen the terminal and try again.

    3.3 Resolve Network Timeouts

    Errors such as ETIMEDOUT and ECONNRESET usually indicate a network or registry connection problem.

    Check the current npm registry:

    1. npm config get registry

    If you are using a mirror that is unstable, switch back to the official npm registry:

    1. npm config set registry https://registry.npmjs.org/

    If the installation still fails, return to Section 1.4 and check your proxy settings before trying again.

    3.4 Remove Leftovers from Older Versions

    Previous installations of similar tools or older versions may leave conflicting commands or configuration files behind.

    List globally installed packages:

    1. npm ls -g --depth=0

    Remove packages you no longer use:

    1. npm uninstall -g package-name

    Before uninstalling anything, back up your user configuration directories when appropriate.

    4. Troubleshooting Checklist

    Work through the following checks in order:

    1. Confirm that Node.js is installed and that its major version is 18 or later.
    2. Confirm that npm is available with npm -v.
    3. Confirm that Git is installed and available with git --version.
    4. Check whether the network can reach the required official services.
    5. Verify proxy variables if your network requires a proxy.
    6. Check npm’s configured proxy and registry.
    7. Confirm that the npm global directory is writable by your user account.
    8. Verify that the npm global bin directory is included in PATH.
    9. Remove conflicting global packages or leftover older versions.
    10. Run claude --version to confirm that the installation is complete.