Setting Up an AI Coding Environment from Scratch: Installation, Configuration, and Model Switching
A step-by-step guide to setting up an AI coding environment. It covers installing Node.js and Git, installing the Claude Code command-line tool, and configuring model providers, with troubleshooting for common permission and download problems. Command examples are shown for Windows, macOS, and Linux.
Introduction: Why Environment Setup Often Gets Stuck
Many developers want to use AI to help with coding but stop at the first step. The command-line tool fails to install, the default model is not accessible, or they do not know which file to change when they want to switch model providers. Most of these problems come from missing prerequisites, incorrect permission settings, and incomplete configuration entries.
This guide breaks the process into four stages: preparing the runtime environment, installing the command-line tool, getting a model switching tool, and adding a model provider and verifying the setup. Claude Code is used as the example command-line tool. Other tools of the same kind follow the same approach, but use the commands in the official documentation for each specific tool.
Stage 1: Prepare Node.js and Git
Most AI coding command-line tools are distributed through npm, which is installed together with Node.js. Working with code repositories requires Git. Confirm that both are available first. If they are already installed and up to date, you can skip this stage.
Windows users can run the following in PowerShell:
winget install OpenJS.NodeJS.LTSwinget install Git.Git
After the installation finishes, close the current terminal, open a new one, and check the versions:
node --versionnpm --versiongit --version
macOS users can use Homebrew. Run the following in Terminal:
brew install node gitnode --versionnpm --versiongit --version
If all three version commands print version numbers, the environment is ready. If a command is not found, the terminal session usually has not loaded the new environment variables. Opening a new terminal normally fixes this. If the error persists, check whether the installer completed successfully.
Use the LTS (Long-Term Support) version of Node.js. Non-LTS versions may be incompatible with some tools.
Stage 2: Install the Command-Line Tool
Run the installation in the built-in terminal of your code editor. After installation, you can start the tool directly from your project directory, and reading and writing files and running terminal commands will work smoothly.
For Claude Code, the npm package name is @anthropic-ai/claude-code. The installation method may change between versions, so check the official documentation before installing. If the official documentation provides a native installer, use the native installer first.
Windows users should open PowerShell as administrator and run:
npm install -g @anthropic-ai/claude-codeclaude --version
macOS and Linux users should avoid using sudo directly. A safer approach is to point npm’s global directory to a directory in the user’s home folder:
mkdir -p ~/.npm-globalnpm config set prefix '~/.npm-global'echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.zshrcsource ~/.zshrcnpm install -g @anthropic-ai/claude-codeclaude --version
If you use bash, replace ~/.zshrc with ~/.bashrc.
You may run into two kinds of problems during installation. The first is permission errors. On Windows, you can retry in an administrator terminal. On macOS and Linux, change the npm prefix as shown above instead of relying on sudo. The second is slow downloads or timeouts. If your network allows it, you can switch to an npm mirror from a trusted source. After installation, consider switching back to the official npm registry so you do not depend on a third-party address over the long term.
When you run claude for the first time, the tool guides you through login or initialization. Follow the prompts to complete the setup.
Stage 3: Get a Model Switching Tool
By default, the command-line tool connects only to its official service. To connect models from other providers, you need to edit the tool’s configuration file. Manual editing is error-prone. A provider switching tool
