Upgrading Node.js to latest version

2019-01-03 03:51发布

So, I have Node.js installed and now when I tried to install Mongoosejs I got an error telling me that I don't have the needed version of Node.js (I have v0.4.11 and v0.4.12 is needed).

How can I upgrade to this version? I suppose I just could install it again with the latest version, but I don't want to do it before I'm sure that my project folders in the folder "node" won't be deleted.

29条回答
看我几分像从前
2楼-- · 2019-01-03 04:04

Windows 10

Open CMD in folder C:\Program Files\nodejs\node_modules and type npm i npm

查看更多
beautiful°
3楼-- · 2019-01-03 04:06

2018 Solution Without sudo!

The Current/Stable "LTS" version of node is 10.13.0 (2018-11-01) see: nodejs.org for latest.

Step 1 - Get NVM (Node Version Manger)

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash

If you're curious about the installation command read the source code
... its been reviewed by several security experts

Step 2 - Install the version of node.js you need

Once you've got NVM you can install a specific version of Node.js using the nvm command:

nvm install v10.13.0

Note: you may need to close & re-open your terminal window for nvm command to be available.

You should expect to see something like this in your terminal:

Now using node v10.13.0

Step 3 - Enjoy the rest of your day!

Yes, it's that easy and didn't require sudo!
Now please Upvote this (so others can avoid sudo-installing things!)
and have a lovely day writing node.js code!

Microsoft Windows User? See: https://github.com/coreybutler/nvm-windows

 tl;dr

Review of the node mailing list indicates that using NVM (Node Version Manager) is the preferred way to manage your nodejs versioning/upgrading. see: github.com/creationix/nvm

NVM by Tim Caswell (& friends) is "better" than N from visionmedia (TJ Holowaychuk) github.com/visionmedia/n because the verbose commands mean is much easier to keep track of what you are doing in your Terminal/SSH Log. Its also faster, saves kittens by not requiring sudo and is used by the team at liftsecurity.io the node.js security experts!

Also worth noting: NVM has almost three times as many GitHub Stars as N (22896 vs 8040). That's usually - but not always - a sign of a better module... feel free to correct if you have evidence of otherwise ...

P.S. this may be a dupe of How can I uninstall or upgrade my old node.js version?

查看更多
男人必须洒脱
4楼-- · 2019-01-03 04:06

There is good explanation for linux users how to update node version step by step. P.S type instead of sudo n stable sudo n latest for receive latest node version.

If you receive following error

Error: Module version mismatch. Expected 48, got 46.

You have just rebuilt npm by the following command npm rebuild it should fix the problem.

查看更多
聊天终结者
5楼-- · 2019-01-03 04:07

For Ubuntu

Install the nvm (Node Version Manager) using the below command

To install or update nvm, one can use the install script using cURL:

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash

or Wget:

wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash

check if nvm is already installed

nvm --version

To install or update node, run below command:

nvm install 10.14.1(the version of node one want to install)

To check the list of node version available to the system or currently running for the system, run the below command:

nvm list

It will list all the available node version present in the system

check the node version:

node -v

查看更多
姐就是有狂的资本
6楼-- · 2019-01-03 04:08

You don't need to worry about an upgrading process.

You can just install the newest version using the official documentation as if you didn't have it installed and it will work like a charm. > https://nodejs.org/en/download/package-manager/ ;)

查看更多
戒情不戒烟
7楼-- · 2019-01-03 04:08

If Node install script doesn't work for you (it didn't for me), here's the solution to update Node Js in Debian Jessie, taken from the reply from Thomas Ward at askubuntu.com (Thanks, buddy!).

1.- Create a new file: /etc/apt/sources.list.d/nodesource.list

You'll need to create this file with sudo, but when you create the file, put this inside it:

deb https://deb.nodesource.com/node_9.x jessie main
deb-src https://deb.nodesource.com/node_9.x jessie main

Then, save the file. (replace node_9.x with the desired version)

2.- Download the GPG Signing Key from Nodesource for the repository. Otherwise, you may get NO_PUBKEY errors with apt-get update:

curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add -

3.- Manually run sudo apt-get update.

This refreshes the data from the nodesource repo so apt knows a newer version exists.

If you get a NO_PUBKEY GPG error, then go back to Step 2

4.- Check apt-cache policy nodejs output.

This is not done by the script, but you want to make sure you see an entry that says something like this in the output:

Version table:
 *** 9.2.0-1nodesource1 0
        500 https://deb.nodesource.com/node_9.x/ jessie/main amd64 Packages
        100 /var/lib/dpkg/status
     0.10.29~dfsg-2 0
        500 http://ftp.debian.org/debian/ jessie/main amd64 Packages

If you do not see entries like this, and only see 0.10.29, start over. Otherwise, proceed.

5.- Install the nodejs binary. Now that you have confirmed 9.x is available on your system, you can install it: sudo apt-get install nodejs

nodejs -v should now show v9.2 or similar on output (as long as it starts with v9. you're on version 9 then).

查看更多
登录 后发表回答