npm can manage developer commands independently of a project's dependencies. OpenAI Codex CLI is available as OpenAI's @openai/codex package, which provides the codex command after a global installation.
Use a 64-bit macOS, Linux, or Windows environment with a maintained Node.js LTS release and npm already available. On Windows with WSL, Codex requires WSL2, with Node.js installed inside the Linux distribution.
Global npm packages follow the active Node.js installation, so switching runtimes with a version manager can also change which Codex command is available. Installing the package and checking its version need no sign-in; authentication is a separate requirement for using OpenAI models.
Steps to install OpenAI Codex CLI with npm:
- Inspect npm's global prefix for the active Node.js runtime.
$ npm prefix -g /home/reader/.nvm/versions/node/v22.23.5
The prefix must be writable by your user; a system-owned prefix can cause EACCES. Adding sudo would give package code root privileges. If the prefix is not writable on macOS, Linux, or WSL2, the linked nvm setup provides a user-owned runtime.
Related: Set up a user-managed Node.js runtime with nvm - Install the official OpenAI Codex CLI package globally.
$ npm install -g @openai/codex added 2 packages in 8s
The -g option installs the terminal command under the active global prefix rather than adding a dependency to the current project. This is the npm installation command documented by OpenAI.
- Confirm that the global package list contains @openai/codex.
$ npm ls -g @openai/codex /home/reader/.nvm/versions/node/v22.23.5/lib `-- @openai/codex@0.167.2
The installed version and directory can differ. An empty list means the package is absent from the active npm prefix.
- Check which codex executable the shell resolves.
$ command -v codex /home/reader/.nvm/versions/node/v22.23.5/bin/codex
On macOS, Linux, and WSL2, the command should come from the prefix's bin directory. In native Windows PowerShell, use Get-Command codex instead; npm places executables directly in its prefix, usually %AppData%\npm. That directory must be on PATH. If another installation appears, that copy takes precedence. A new terminal picks up saved PATH changes; with nvm, the selected Node.js version determines the global package directory.
- Confirm that the installed Codex CLI starts and reports the package version. Example output:
$ codex --version codex-cli 0.167.2
The version should match the @openai/codex entry above. A version mismatch indicates that another Codex installation is answering the command.
Related: Start a Codex interactive session