Set node version individually for each project


If you develop multiple projects at the same time, and the node version required by each project is different, then you need to set the node version separately for each project.

Several version management tools are introduced on the node official website, including: n, nodenv, nvm.

Installing Node.js via Package Manager

 

In the description of nodenv, it is written that it can be set individually for each project without affecting the overall situation, so the following describes how to use nodenv in detail.

First, install nodenv
with brew install nodenv. On nodenv’s official website, it is found that nodenv-vars is needed to set up different environments. Then follow the instructions. In the nodenv
installation directory, here is /usr/local/Cellar/nodenv/1.4.1, create a new plugins directory, and then git clone https://github.com/nodenv/nodenv-vars.git.

2. Setting up shims (Shims)
is actually to configure the nodenv command in the environment variable Path, and configure it in front

~/.nodenv/shims:/usr/local/bin:/usr/bin:/bin

I took a look at the ~/.nodenv/shims directory. There are several commands like npm node in it, which means that when you execute node in the future, what you actually execute is the node in ~/.nodenv/shims, which is equivalent to acting as a proxy.

Three, use

Which version needs to be installed, use nodenv install xxx to install, such as: nodenv install 14.17.6

In the root directory of the project, use nodenv local 14.17.6 to indicate that the project uses the 14.17.6 version of node. At the same time, you will find that there are more .node-version files in the directory, which contain the version number. At this time, use cnpm run build --verbose and you will see that you have switched to version 14:

nodenv versions : Check which versions are currently installed on the computer

nodenv version: View the version of the current project

After installing some global npm packages, run once:

nodenv rehash

Guess you like

Origin blog.csdn.net/bokix/article/details/130926114