codex icon indicating copy to clipboard operation
codex copied to clipboard

how to switch node version

Open samuelstroschein opened this issue 4 months ago • 12 comments

What is the type of issue?

Documentation is missing

What is the issue?

How can the node version that codex uses be changed?

It uses Node v18 by default. Prompting Codex to use nvm to switch the node version doesnt work. Here is a response that Codex gave

✓ Completed
  └ ⌨️ echo "Checking for nvm..."; command -v nvm ||
echo "nvm not found"; echo "PATH=$PATH"; echo "Node
version:"; node -v

codex
I checked: this sandbox doesn’t have nvm available,
and Node is fixed at v18.16.0 for this session.

- nvm: not found
- PATH: shows host paths, but no nvm loader present
here
- node -v: v18.16.0

In another session on your machine you can absolutely
use nvm to switch to Node 22. In this Codex CLI
sandbox, the runtime is tied to the host image and
can’t be changed from inside the session. If you
want me to keep making progress here despite Node 18,
I can:

- Add a tiny vitest setup file to polyfill CustomEvent
so tests run under Node 18.
- Or flip specific tests to jsdom environment.

Where did you find it?

No response

samuelstroschein avatar Aug 19 '25 00:08 samuelstroschein

In this session, I would like you to use Node 20 instead of the default 22. Can you switch the version using nvm via zsh? Then, use the switched node version for the following operations. Also, ensure each command runs with nvm use 20 in-session.

A prompt like this can work for your use case, but it's inefficient. So, I'd recommend simply running nvm use or having .nvmrc before starting a codex session.

seratch avatar Aug 19 '25 01:08 seratch

Okay, so codex runs my shell correct?

If so, I need to figure out why it picks up v18 while my default is v22. The sandboxing stuff confused me. Codex said changing the node version is not possible because codex runs in a sandbox container which defaults to v18.

I'll try to fix the issue on my end tmr and report back

samuelstroschein avatar Aug 19 '25 04:08 samuelstroschein

The bug seems to emerge because the default shell on mac os is zsh but codex runs in bash. The outcome are different environments.

Prob a good idea to use the default shell on the machine for codex?

samuelstroschein avatar Aug 19 '25 18:08 samuelstroschein

nvm is just a bulky bash script which needs to be loaded for each shell session. So if you bootstrap nvm in zshrc file it might not be available because afaik codex executes commands in non-interactive mode.

xorgal avatar Aug 21 '25 04:08 xorgal

Having same issue

Meabo avatar Sep 17 '25 14:09 Meabo

Same here - using nvm to manage node, but sandbox is stuck on 18

alexolivier avatar Sep 19 '25 11:09 alexolivier

Same here, i use node v22, but sandbox is on 18

hellodigua avatar Sep 27 '25 03:09 hellodigua

Codex CLI in my case was using the Node.js binary from /usr/local/bin/node. The workaround is to upgrade that global Node.js installation.

  • Navigate to this page: https://nodejs.org/en/download
  • Choose macOS and click "macOS Installer (.pkg)" at the bottom
  • The installer installs the updated Node.js to /usr/local/bin/node and Codex picks it up

It doesn't solve the fact that Codex should probably use nvm out of the box.

matteocontrini avatar Sep 27 '25 09:09 matteocontrini

I had the same issue and solved. The reason is I had multiple node, and my zsh shell uses the homebrew one, but the sandbox uses the /usr/local/bin/node one.

Just tell codex to run the following commands, then you know the problem:

which -a node
node -v
node -p "process.execPath"

For me, since I use the homebrew one, so my solution is simply deleting the lower version sudo rm -f /usr/local/bin/node.

levi0214 avatar Sep 27 '25 11:09 levi0214

same issue..

Tarek-kharsa avatar Oct 14 '25 11:10 Tarek-kharsa

same here

rdgomt avatar Nov 10 '25 14:11 rdgomt

I had the same issue and solved. The reason is I had multiple node, and my zsh shell uses the homebrew one, but the sandbox uses the /usr/local/bin/node one.

Just tell codex to run the following commands, then you know the problem:

which -a node
node -v
node -p "process.execPath"

For me, since I use the homebrew one, so my solution is simply deleting the lower version sudo rm -f /usr/local/bin/node.

This was the one thing that worked for me

thitemple avatar Nov 12 '25 10:11 thitemple