This article describes how to install the npm package ** n **, which enables version control of Node.js, and how to change the version of Node.js using n. Note that * npm package n is not supported natively on Windows *, so it targets non-Windows environments such as Linux and macOS.
--Those who already have Node.js installed --Those who want to downgrade Node.js to a previous version --If the OS is Linux or mac
I usually make sure that Node.js on my development PC has the latest LTS version installed. \ (It was v12.16.1 as of 2020/03/06 ) But recently, that caused some trouble.
The currently supported LTS versions of NodeJS for the SharePoint Framework are both Node.js v8.x and Node.js v10.x.
I was wondering what ... \ (Microsoft, please update as soon as possible ... ), but when I think back, I used version control packages for other languages such as `pyenv, goenv, and exenv. I noticed that I put it in, but I didn't put it in Node.js **.
So, refer to [npm trends] npm-trends-n-nodeenv-nvm and downgrade the Node.js version using the most popular Node.js version control package ** n **. I decided to try it.
Globally install npm package n from the npm repository.
sudo npm install -g n
After the installation is complete, we will actually change the version of Node.js.
There are the following notes for npm package n.
The global packages are not changed by the install, with the exception of itself which is part of the install. (The global package is not modified by the installation, except for itself, which is part of the installation.)
This means that changing the version with n will make the following changes to the globally installed npm package:
--Node.js version will change --The version of npm has also changed. It will change depending on the version of Node.js. --No version changes (not affected) except Node.js and npm
Therefore, before actually changing the version of Node.js, it is recommended to check what is globally installed in your environment and consider the impact of the change.
Check for globally installed packages
npm list -g
Execution result
/usr/local/lib
├── [email protected]
├─┬ [email protected]
...
└── [email protected]
In my case, besides n and npm, yarn is installed globally.
Check the version information that can be downgraded.
Check the list of switchable versions
n ls-remote --all
Execution result
13.10.1
13.10.0
13.9.0
...
11.0.0
10.19.0
10.18.
...
0.8.6
This time, we're downgrading to v10.19.0, the final version of v10.x.
Downgrade
sudo n 10.19.0
Execution result
installing : node-v10.19.0
mkdir : /usr/local/n/versions/node/10.19.0
fetch : https://nodejs.org/dist/v10.19.0/node-v10.19.0-darwin-x64.tar.xz
installed : v10.19.0 (with npm 6.13.4)
After running, check the version of Node.js and it should switch to v10.19.0.
Version confirmation
node -v
Execution result
v10.19.0
If you want to revert the Node.js version to the latest LTS version, run the following command:
sudo n lts
-[10 Node.js frameworks to check] RelLink1 -[Start Node.js development using Docker container] RelLink2
Node.js
n
Qiita
-[Node.js environment construction memo] Qiita1 -[\ [Node.js ] Introducing Node.js (Linux / Mac)] Qiita2 -[Organize and uninstall Node.js, npm, n] Qiita3
Recommended Posts