How node. js version management tool n is ineffective

Source: Internet
Author: User
Introduction to the principle and solution of node. js version management tool n

N is a module of node. It can be used to manage various versions of node. It is similar to Python's rbenv and Ruby's rbenv. The author of n is the famous corner stone.

Install n through npm:

$ npm install -g n

View the current node version:

$ node -vv4.2.4

Use n to install the specified version:

$ n 4.4.4install : node-v4.4.4    mkdir : /opt/node/n/versions/node/4.4.4    fetch : https://nodejs.org/dist/v4.4.4/node-v4.4.4-linux-x64.tar.gz###################################100.0%  installed : v4.2.4

Check the current node version:

$ Node-vv4.2.4 # same as the original

Solution

If you find that the node version remains unchanged like me, it is most likely that the installation directory of your node is different from the default path of n.

View the current node installation path:

$ Which node/opt/node/bin/node # example

The default installation path of n is/usr/local. If your node is not in this path, n cannot replace bin, lib, include, and share in this path, therefore, we must use the N_PREFIX variable to modify the default node installation path of n.

Edit the environment configuration file:

vim ~/.bash_profile

Insert the following two lines of code to the end of the file:

Export N_PREFIX =/opt/node # actual node installation location export PATH = $ N_PREFIX/bin: $ PATH

: Wq save and exit;

Execute source to make the modification take effect.

$ source ~/.bash_profile

Check whether the environment variables take effect:

echo $N_PREFIX/opt/node

At this time, we need to reinstall:

$ n 4.4.4install : node-v4.4.4    mkdir : /opt/node/n/versions/node/4.4.4    fetch : https://nodejs.org/dist/v4.4.4/node-v4.4.4-linux-x64.tar.gz##############100.0%  installed : v4.4.4

Check the current node version:

$ node -vv4.4.4

Indicates that the modification is successful.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.