Qwen Code CLI: Setup and Teardown on Ubuntu
Qwen Code CLI is a lightweight command-line interface for AI-assisted coding tasks. It was open-sourced by Alibaba (forked from Gemini CLI) and optimized for the Qwen3-Coder models . In practice, you can use it with various AI models (OpenAI/GPT, xAI Grok, etc.) by configuring the API credentials. The CLI lets you explore codebases, refactor functions, generate tests, and more via simple prompts.
Installing Node.js (via NodeSource)
The CLI is built on Node.js, requiring Node.js v20 or later . On Ubuntu, the recommended way is to use NodeSource’s PPA:
Add NodeSource PPA:
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
Install Node.js:
sudo apt-get update
sudo apt-get install -y nodejsThis will install Node.js (and npm) from NodeSource, giving you an up-to-date version . You can verify the install with node -v and npm -v.
Installing Qwen Code CLI
With Node.js in place, install the Qwen Code CLI globally via npm:
npm install -g @qwen-code/qwen-code@latest
qwen --versionThe first command fetches the @qwen-code/qwen-code package and makes the qwen command available system-wide. Running qwen --version should show the installed version (e.g. 0.0.11) , confirming the CLI is set up.
Configuring API Credentials
Qwen Code needs API credentials to talk to AI models. You can use OpenAI-compatible keys by setting environment variables. For example:
export OPENAI_API_KEY="YOUR_OPENAI_API_KEY"
export OPENAI_BASE_URL="https://api.openai.com/v1"
export OPENAI_MODEL="gpt-4"These exports (or equivalent entries in a .env file) tell Qwen Code which model and endpoint to use . For instance, to use Alibaba’s Qwen3-Coder model via OpenRouter, you might set OPENAI_BASE_URL="https://openrouter.ai/api/v1" and OPENAI_MODEL="qwen/qwen3-coder".
Tip: If you prefer Qwen’s OAuth login flow, simply running qwen without keys will open a browser for Qwen account authentication (no manual setup needed) .
System Requirements
OS: Any modern Ubuntu (e.g. 18.04, 20.04, 22.04) or other Linux x86_64. Qwen CLI is cross-platform (also works on macOS).
Node: Node.js 20.x or higher is required .
CPU & RAM (Basic): Because the heavy AI work is remote, even a small VM (1–2 vCPU, ~1 GB RAM) can run the CLI for simple prompts.
CPU & RAM (Comfortable): For handling large codebases and fast response, use a multi-core CPU and 4+ GB RAM. The CLI processes code and context locally before sending it to the AI service, so extra RAM/CPU helps with large repositories.
Disk: The CLI and its cache use a few tens of MB. Make sure you have at least 100 MB free.
Network: A stable Internet connection is required, since queries and code history are sent to remote AI APIs.
In short, any up-to-date Ubuntu machine with Node 20+ and Internet access is enough for basic use. More CPU/RAM speeds up large-code analysis.
Verifying the CLI
After installation and configuration, you can run the CLI to check it works. For example, qwen --version should print the version. You can also run an “about” command (if available) to see details:
Example output of qwen about (or similar) showing CLI version and model. Running qwen about (or qwen info) displays the CLI’s metadata: version, Git commit, active model, OS, and auth method. In the example above it shows “Version 0.0.11”, model “x-ai/grok-code-fast-1” (XAI Grok), and that it’s using OpenAI-compatible auth. This confirms the CLI is installed correctly and points to which AI backend it will use.
You can now run qwen in any project directory. It will prompt you to type messages or use commands like /clear or /stats to manage the session. See official docs for usage examples.
Uninstalling Qwen Code CLI
To remove Qwen Code and clean up:
Uninstall the global npm package:
sudo npm uninstall -g @qwen-code/qwen-code
Clear npm cache (optional but recommended):
npm cache clean --force
Remove CLI configuration: Delete the Qwen settings directory (e.g. session history):
rm -rf ~/.qwenThis removes any saved settings or histories.
Clear environment variables: If you added export OPENAI_… lines to your shell config (~/.bashrc or ~/.profile), remove those lines. In the current shell you can also run:
unset OPENAI_API_KEY OPENAI_BASE_URL OPENAI_MODEL
(Optional) Uninstall Node.js: If you only installed Node.js for Qwen and want to remove it, do:
sudo apt remove nodejs
sudo apt purge nodejs
sudo apt autoremoveThis removes Node.js and npm from your system . If you used nvm or other methods, use the corresponding uninstall procedure.
After these steps, the Qwen CLI and all its traces will be gone from your server.
Summary
Qwen Code CLI is a developer-focused AI coding assistant, ideal for navigating complex codebases, refactoring, generating tests, and creating documentation . Install it on Ubuntu by adding NodeSource’s Node.js 20+ repository, installing Node.js, then running npm install -g @qwen-code/qwen-code . Set your OPENAI_API_KEY (and related variables) to point to an AI model (OpenAI, XAI Grok, or Qwen’s own models) .
When you’re done experimenting, use the above steps to uninstall: remove the npm package, clear the ~/.qwen directory, unset any env vars, and optionally uninstall Node.js to keep the system clean. By following this setup/teardown loop, cloud engineers can quickly test Qwen Code CLI and then restore the server to its original state.
References: Official Qwen Code CLI docs and guides .
Last updated