Simple talk about Node.js version control NVM and N_node.js

Source: Internet
Author: User
Tags mkdir install node git clone

Today's topic consists of 2 parts

1. Use NVM or N for version control under Node.js
2. NVM install node.js version, restart terminal node, NPM environment variable failure

The first part uses what to manage the Node.js version

First of all, we should cheer and celebrate. Node.js finally released a historic official version of 1.0, although we see V4.0, in fact, he is node.js the true meaning of 1.0, io.js live up to expectations, completed its mission.

Looking back on the development of Node.js and io.js over the years, the iterations of various editions, it is necessary to use a Node.js version management tool to control the Node.js version of the current system.

Why did you do that?

The latest V8 engine, all the new features of ES 6, have been used in the new version. Can you stand it?
However, if you are reckless upgrade, the first problem is that your development environment and online publishing environment may be different, then the consequences will not be much, there are problems waiting for the boss to whip the corpse.
The second problem may be that some of the previous open source packages need to be recompiled, especially by the C + + module.

So, you need a node.js version management software

What are the popular Node.js version management now?

Nvm

We use Brew to install NVM

Brew Install NVM

Here's to note
After the brew is installed, be sure to set it up in your bash or zsh configuration file, or when you reboot the terminal, you will find node, NPM environment variables are invalidated

Here's a second topic that we're going to share.
NVM after reboot terminal node, NPM failure solution

If you use the installation method of the brew above
When the installation is successful, follow these steps to set up your shell configuration file

Brew Info NVM

You will see the following output Help information

Nvm:stable 0.26.1 (bottled) head
Manage multiple node.js versions HTTPS://GITHUB.COM/CREATIONIX/NVM
/ usr/local/cellar/nvm/0.26.1 (3173 files, 56M) *
 poured from bottle
from:https://github.com/homebrew/homebrew /BLOB/MASTER/LIBRARY/FORMULA/NVM.RB
==> caveats
Add NVM ' s working directory to your $HOME path (if it doesn ' t e Xist):

 mkdir ~/.nvm

Copy 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 ' s
equivalent configuration file:

 export Nvm_dir =~/.NVM
 Source $ (Brew--prefix NVM)/nvm.sh

Type ' NVM help ' for further information.

Bash completion has been installed to:
 /USR/LOCAL/ETC/BASH_COMPLETION.D

We need to follow the method provided above to create the. nvm file in the user's directory first

mkdir ~/.NVM

Then copy the Nvm-exec file to the new. NVM directory you just created.

CP $ (Brew--prefix NVM)/nvm-exec ~/.nvm/

Then edit your bash profile $HOME/.BASHRC, and if you use zsh then edit $HOME/.ZSHRC config file

Nano ~/.BASHRC

Or

Nano ~/.ZSHRC

Paste the following contents into the

Export NVM_DIR=~/.NVM
Source $ (Brew--prefix NVM)/nvm.sh

Finally let your shell configuration take effect in time

SOURCE ~/.BASHRC

Or

' Source ~/.ZSHRC '

In the end, you will not be able to turn off the terminal reboot, or reboot the machine to discover node, NPM and other system environment variables fail.

The difference between NVM and n

NVM is similar to Python's virtualenv or Ruby's RVM, which is an independently installed software
n is actually a NPM global open source package that needs to be installed globally using NPM
n is lighter, but nvm more independent.

If you have a new computer, if you want to use version management, then NVM is your choice, because it's standalone software that you can download at will after installing the version you need.

But n is dependent on a package under NPM, which means that your computer environment is not NODE/NPM, you still can't use N.
So when you use it, you can weigh it against your own situation. I personally use NVM to control the node version.

NVM use

To view the version that can be installed

NVM ls-remote

View the version that has been installed

NVM ls

To install a specified version

NVM Install <version>

The version above can specify the number of versions you have listed in NVM ls-remote.

Delete the specified version

NVM use <version>

Installation of n

NPM install-g N

Of course, you can also go to github download your source code locally compiled

$ git clone https://github.com/visionmedia/n.git
$ cd n
$ [sudo] make install
n install specified version
n stable/laster/& Lt Version>

In the back of the N more a logo stable identification of the latest stable version, Laster logo The latest version of,<version> you can specifically specify a version number

N using a version
n use <version>

n Delete a version
n RM <version>

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.