Brief Introduction to node. js version control nvm and n_node.js

Source: Internet
Author: User
Thanks to the contributions of a large number of developers, the Node version has a fast iteration speed and many versions (from 0.6 to 0.11). Therefore, upgrading the Node version has become a problem. At present, there are n and nvm tools that can be used for painless Node upgrade. This article briefly introduces the use of the two tools. Today's topic includes two parts

1. Use nvm or n for version control under node. js
2. After the node. js version is installed on nvm, restart the terminal node. The npm environment variable is invalid.

Part 1 What to use to manage node. js versions

First, we should celebrate node. js finally released the historic official version 1.0. Although we see V4.0, it is actually a node. 1.0 of the true meaning of js, io. js has fulfilled its mission.

Looking back at the past few years of node. js and io. js development speed, iterative release of various versions, we need to use a node. js version management tool to control the node of the current system. js version.

Why?

The latest V8 engine has been used in the new version. All the new features of elasticsearch 6 are ready for use. Can you bear it?
However, if you upgrade your development environment in a reckless manner, the first problem may be that your development environment may be different from the online release environment, so there will be no more consequences. If something goes wrong, wait for the boss to throw the zombie.
The second problem may be that some of the previous open source packages need to be re-compiled, especially written by the c ++ module.

Therefore, you need a version management software for node. js.

What are the popular node. js version management features?

Nvm

We use brew to install nvm

brew install nvm

Note that
After brew is installed, you must set it in your bash or zsh configuration file. Otherwise, when you restart the terminal, you will find that node and npm environment variables are invalid.

Here is the second topic we will share.
Solution for terminal node and npm failure after nvm restart

If you use the brew installation method above
After the installation is successful, set your shell configuration file as follows:

brew info nvm

You will see the following output help information

nvm: stable 0.26.1 (bottled), HEADManage multiple Node.js versionshttps://github.com/creationix/nvm/usr/local/Cellar/nvm/0.26.1 (3173 files, 56M) * Poured from bottleFrom: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/nvm.rb==> CaveatsAdd NVM's working directory to your $HOME path (if it doesn't exist): mkdir ~/.nvmCopy nvm-exec to NVM's working directory cp $(brew --prefix nvm)/nvm-exec ~/.nvm/Add the following to $HOME/.bashrc, $HOME/.zshrc, or your shell'sequivalent configuration file: export NVM_DIR=~/.nvm source $(brew --prefix nvm)/nvm.shType `nvm help` for further information.Bash completion has been installed to: /usr/local/etc/bash_completion.d

First, create the. nvm file in the user directory.

mkdir ~/.nvm

Then copy the nvm-exec file to the. nvm directory you just created.

cp $(brew --prefix nvm)/nvm-exec ~/.nvm/

Then edit your bash configuration file $ HOME/. bashrc. If you use zsh, edit the $ HOME/. zshrc configuration file.

nano ~/.bashrc

Or

nano ~/.zshrc

Paste the following content

export NVM_DIR=~/.nvmsource $(brew --prefix nvm)/nvm.sh

Finally, let your shell configuration take effect immediately

source ~/.bashrc

Or

`source ~/.zshrc'

In the end, you will not restart the terminal, or restart the machine to find that the system environment variables such as node and npm are invalid.

Differences between nvm and n

Nvm is similar to Python virtualenv or Ruby rvm. It is an independently installed software.
N is actually an npm global open-source package, which requires npm for global installation.
N is more lightweight, but nvm is more independent.

If you have a new laptop and you want to use version management, nvm is your choice. Because of its independent software, you can download and switch the desired version at will after installation.

However, n is dependent on a package in npm. That is to say, when your computer environment does not have node/npm, you still cannot use n.
Therefore, when using this tool, you can weigh your own situation. I use nvm to control the node version.

Nvm usage

View available versions

nvm ls-remote

View installed versions

nvm ls

Install a specified version

nvm install 
 

The version above can specify the version number listed in nvm ls-remote.

Delete a specified version

nvm use 
 

N Installation

npm install -g n

Of course, you can also download your source code from github and compile it locally.

$ Git clone https://github.com/visionmedia/n.git$ cd n $ [sudo] make installn install the specified version n stable/laster/<version>

Next to n, add the stable ID to the latest stable version, and laster to the latest version, You can specify a version number.

N use a single version n use
 
  
N delete a version n rm
  
 
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.