abdulbari
abdulbari

Reputation: 6242

NVM doesn't switch the expected Node.js version

I want to use an older version of Node.js in my application, and for that I have attempted to use nvm so that I can change the version accordingly.

Now I have three versions of Node.js and want to switch on specific version

nvm use [selected version]

It is successfully executed but the version is not updated

Example of use:

enter image description here

Upvotes: 0

Views: 6210

Answers (4)

Vivek Dhage
Vivek Dhage

Reputation: 1

Since nvm alias default 6.11.2 is already set correctly but the terminal still defaults to 8.9.4, the issue might be with how your shell loads nvm. Follow these steps to fix it:


1. Ensure NVM is Loaded in Your Shell

Check if nvm is properly sourced in your shell config file (.bashrc, .bash_profile, or .zshrc).

For Bash (.bashrc or .bash_profile)

Open your .bashrc file:

nano ~/.bashrc

Ensure these lines exist at the bottom:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"

nvm use default

Save and exit (Ctrl + X, then Y, then Enter).

Apply changes:

source ~/.bashrc

For Zsh (.zshrc)

If you use Zsh, edit .zshrc:

nano ~/.zshrc

Add:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

nvm use default

Save, then apply changes:

source ~/.zshrc

2. Verify the Default Version

Close and reopen the terminal, then run:

node -v

It should return 6.11.2. If not, try:

nvm use 6.11.2
nvm alias default 6.11.2

Then restart the terminal.


3. Check for Conflicting Node Versions

Sometimes, a system-wide Node.js version (/usr/bin/node) conflicts with nvm. Check if this is the case:

which node

If it returns /usr/bin/node, then your system Node.js is overriding nvm. To fix this, remove it (if you don’t need it):

sudo apt remove nodejs

Then restart the terminal.

Upvotes: 0

I had encountered this before. I removed the old Node.js installed in my machine, re-install the NVM and it works like a charm.

Upvotes: 0

Anjum....
Anjum....

Reputation: 4204

If your nvm command not updating your node version in windows, for example

Your current version is 6.11.2 and you would like to update to 8.11.3 using nvm use 8.11.3 in windows OS then below hack will do that job.

Renamed C:\Program Files\nodejs to C:\Program Files\nodejsx it worked for me.

Credit goes to user ituasdu

Upvotes: 5

melwil
melwil

Reputation: 2553

From the readme of NVM, under important notes:

Note: nvm does not support Windows (see #284). Two alternatives exist, which are neither supported nor developed by us:

  • nvm-windows
  • nodist

Upvotes: 1

Related Questions