congtrungvnit
congtrungvnit

Reputation: 665

Am I having two different versions of NodeJS on my Mac?

I am new to NodeJS and have installed it through Homebrew. But when I run node --version and npm --version commands, they reports that I have old version, while Homebrew tell me that I have installed the latest version when I try the upgrade command. The result when I run these commands is demonstrated in the following picture. What does this means?

enter image description here

Upvotes: 3

Views: 5015

Answers (2)

hassan
hassan

Reputation: 166

Remove existing Node.js version First of all, let’s remove the existing Node.js version from your computer.

brew uninstall --ignore-dependencies node
brew uninstall --force node

Install NVM using Homebrew Let’s install Node Version Manager (NVM). It will allow us to manage multiple active node.js versions.

brew install nvm

Install Node.js via NVM You can now install a specific Node.js version or install a LTS (Long-term support version).

nvm install --lts
or

nvm install 12.7.0

Now you can switch between different Node.js versions using the following command.

nvm use 16
node -v
v16.17.0

nvm use 12
node -v
v12.7.0

Upvotes: 0

kondrak
kondrak

Reputation: 436

It kind of looks like you may have two different versions of node installed (by different means). Is this the case?

If you don't, you may just need to close/reopen your shell for the new version to take effect, if the installer is comprehensive enough. If that doesn't do the trick, you probably just need to update your environment variables to point to the new version. This will require exporting NODE_HOME in your bash profile (if you're using bash)

If you need to manage multiple versions of node/npm, I would consider using Node Version Manager (nvm)

Upvotes: 1

Related Questions