I cannot switch node.js version - node.js

I am trying to switch my node.js version.
What I did is:
sudo npm cache clean -f
sudo npm install -g n
sudo n 10.10.0
But I check my current version after I did it by using
node -v
It always shows
v6.14.3
I am not sure if I do anything wrong. Any suggestion please?

As stated by Intervalia, try using using NVM (node version manager)
With nvm, you can very easily do things like:
nvm install 10.10.0 and it will download that version of node. And then do nvm use 10.10.0 and then doing node -v will return 10.10.0.
Here is what happens when I run nvm list

Related

How to downgrade node version?

I want to downgrade my version using npm.
The current version is 16.13.1. I want to downgrade this to 12.0.1. Can anyone tell me how to do it?
Thanks!
use node version manager nvm, you can switch any node version that you want.
More details
https://github.com/nvm-sh/nvm/blob/master/README.md
https://www.npmjs.com/package/nvm
nvm install 14.15.5
nvm use 14.15.5
Use below command for all installed node versions
nvm list
You can accomplish that with Node Version Manager. Install nvm first, and in a terminal:
nvm install 12.0.1
Then
nvm use 12.0.1
You can use: npm install -g node#version.
So for example in your case it would be -> sudo npm install -g node#12.0.1
might have to force it with --force at the end.
You could also install the node npm module to change (upgrade or downgrade) the NodeJS version for the specific project.
Try the n package from npm. Find it here.
npm install -g n
n 10.16.0
n lts
Simply execute n <version> to download and install a version of Node.js. If has already been downloaded, n will install from its cache.
first check your node version
node -v
sudo npm install -g n
sudo n stable
sudo n 14.6.0 (you can chnage version here as you want to move)
npm install (jst run after all)
now you can check the node and npm version by
node -v
npm -v
Clearing the local installation of node, to find out where is and delete
where node
Install nvm
For Windows
For others
Show all the versions
nvm ls available
Install what you want
nvm install 12.0.1
nvm use 12.0.1
Check node version
node -v
I have tried several ways and this works, hope it helps.
I finally found a simple solution.
Uninstall the current Version
Download the version you want.
It works fine for me.
Thanks!

How to upgrade node to specific version in macOS Mojave, and update the active path for node?

I want to upgrade node to 12.10.0 and npm to 6.11.3, currently I am working on macOS Mojave version 10.14.5
I am using these commands to upgrade the node version to 12.10.0::
sudo npm cache clean -f (force) clear you npm cache
sudo npm install -g n install n (this might take a while)
sudo n 12.10.0 upgrade to the specific version
After running the last command it gives me an output like::
installing : node-v12.10.0
mkdir : /usr/local/n/versions/node/12.10.0
fetch : https://nodejs.org/dist/v12.10.0/node-v12.10.0-darwin-x64.tar.gz
installed : v12.10.0 to /usr/local/bin/node
active : v10.16.3 at /usr/local/opt/node#10/bin/node
When I am checking for node version node -v it still shows me old version 10.16.3
I have tried to add node path, but still, it gives me the same output.
I have used command sudo nano /etc/path and then added /usr/local/bin/node path to it.
Please suggest me how can I upgrade node to 12.10.0 and npm to 6.11.3 version?
Install nvm following below tutorial :
Install nvm with homebrew
As stated in the link above,
Start by :
brew update
brew install nvm
mkdir ~/.nvm
nano ~/.bash_profile
In your .bash_profile file (you may be using an other file, according to your shell), add the following :
export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh
Back to your shell, activate nvm and check it (if you have other shells opened and you want to keep them, do the same) :
source ~/.bash_profile
echo $NVM_DIR
Then with the help nvm install any node version(example v12.14.1) you want :
nvm install v12.14.1
nvm use v12.14.1
to switch to 12.14.1 version.
Step 1: Clean npm cache
sudo npm cache clean -f
Step 2: Install node helper (n) globally using the following command.
sudo npm install -g n
Once node helper is installed. You can either get a specific version like I needed 16.14.1 then you can perform.
sudo n 16.14.1
OR You can get the latest stable version using
sudo n stable
Then you can confirm the version installed
node --version
install n (npm module) npm install -g n and run sudo n latest or sudo n <version>
An alternate way to upgrade w/o using brew -
Go to nodejs releases page. The table on this page list the various node release available for download.
Click on the downloads link for the version you need. This will take us to another page to download the node version depending on the OS you are using. For mac, we can download the .pkg format.
After the package is downloaded, we can run it by clicking the downloaded file and hitting 'Next' till we complete.

How do I install node 9 with nvm?

Trying but failing; also open to manual install if someone can help.
FYI, end goal is to install mobius-network-js to begin dev on a Mobius DApp
To install node v9.0.0, use
nvm install 9.0.0
Then check the version
node -v
It should be v9.0.0
If there is a version mismatch, use
nvm use 9.0.0
The output should be
Now using node v9.0.0 (npm v5.5.1)
Made sure, you have already installed the nvm
You can also check the Documentation for details.
You can install specific version on node using nvm via
nvm install <node-version> - nvm documentation
if you want to install node v9. you can run nvm install v9 and this will automatically install
the node v9.x.x
you can also set it as the default version via the nvm use command.
Open git bash and and try the following commands:
nvm install [version_needed]
nvm use [version_needed]
Instead of [version_needed] write down the relevant version of nodejs:
https://nodejs.org/en/download/releases/
n library is best alternative of nvm and its really easy to use .
https://www.npmjs.com/package/n
installation step
step 1 -
npm i n -g
step 2 -
n node-version
ex - n 9 or n stable to download latest stable version of node

What would be the way now to install node with npm via brew

I've installed node on my macOS
brew install node
After doing this, node is installed correctly:
$ node -v
v8.4.0
But running
$ npm -v
gives me -bash: /usr/local/bin/npm: No such file or directory
What would be the way now to install node with npm via brew?
brew install node uses by default --without-npm
I had the same problem. I ran $ brew doctor to make sure node was linked first. Then I ran
$ brew postinstall node
$ npm -v should now show the version number.
I stepped into a similar issue, too. My problem was that I still had not a
~/.bash_profile file in place and therefore no place where to actually link my bash command to npm.
Don't use Homebrew to install node.
I like the Node Version Manager (NVM), and there is n. These are better options on a Mac for node, to avoid certain. issues. later. Plus it avoids this question, as these node versions include npm.
Note, you can install nvm and n via Homebrew. (brew install nvm or brew install n).

How to check and change the Nodejs version on Ubuntu?

I am using Ubuntu Linux.
How can I check current nodejs version? I guess, I have 6 version, but I am not sure.
And is there way to change it, because I need 4 version. Can some one give step by step commands?
Open up the terminal and type node -v
To change your node version, I'd recommend installing nvm. Once installed, to switch versions it's as simple as
nvm use <version>
You can check your current NodeJS version by using command node -v.
And changing your version can be done by using node version manager.
The easiest way to do that is by running this $ npm install -g n now you can change your current NodeJS version using n (version)
e.g. n 4.0.0.
node -v
npm install -g n
n 4.0.0
You can check your version by using this code (node -v) in linux terminal and If you want to upgrade it to stable version you can use following codes one by one.
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
Just type npm version in your command line and it will display all the version details about node, npm, v8 engine etc.
To change your node version, I'd recommend installing nvm. Once installed, switch versions follow the instruction below;
nvm use <any specified version you prefer "example v16.0.0">
Example:
nvm alias default 16
This will enforce as the current default version.

Resources