Updating Nodejs on mac

All we need is an easy explanation of the problem, so here it is.

I am using macOS Big Sur and want to update my Node. However, after downloading its file from the official website and completing its installation, my terminal still shows and uses my previous node version.

Does anyone know how can I overcome this issue?

Thanks

terminal screenshot

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

I suggest using nvm. It’s much simpler and eradicates the headache of updating.

nvm

To do this, you can install nvm. https://github.com/nvm-sh/nvm#installing-and-updating

you will be pasting in the curl command curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

Note: when this is finished running, you should see a line near the bottom which says something like export NVM_DIR="$HOME/.nvm"

Copy and paste this and hit enter.

Then check to make sure you have nvm installed now nvm -v

Nodejs update

After, in the terminal, type: nvm install node (you can also check your current version first with node -v

Run it and then check node version again. It should be updated.

npm

While you’re at it, you can also update npm.

Check version npm -v
Update npm install -g npm

This should do it. Let me know if there are any issues. Note: this can all be done in the -zsh shell, no reason to move back to bash.

Method 2

The error displayed was sudo: n: command not found, which hinted that the binary might have not been successfully installed on your system. You need to check the location of n executable by using which command:

$ which n

Reinstalling n with more verbose debug level may also provide you with better information for troubleshooting.

$ sudo npm install --loglevel verbose -g n

Among possible options to install Node.js on MacOS, n was tested to be less error prone as you can read here. You should be on the right direction with the package manager choice.

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply