博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何在Ubuntu上安装Node.js并将npm更新到最新版本
阅读量:2522 次
发布时间:2019-05-11

本文共 4912 字,大约阅读时间需要 16 分钟。

If you try installing the latest version of node using the apt-package manager, you'll end up with v10.19.0. This is the latest version in the ubuntu app store, but it's not the latest released version of NodeJS.

如果尝试使用apt-package Manager安装最新版本的node,最终将得到v10.19.0 。 这是ubuntu应用商店中的最新版本,但不是NodeJS的最新发布版本。

This is because when new versions of a software are released, it can take months for the Ubuntu team to test and release in the official Ubuntu store. As a result, to get the latest versions of any software, we may have to use private packages published by developers.

这是因为发布新版本的软件时,Ubuntu团队可能要花费数月才能在Ubuntu官方商店进行测试和发布。 因此,要获取任何软件的最新版本,我们可能必须使用开发人员发布的私有软件包。

In this tutorial, what we want to do is get either v12.18.1 (LTS - with Long term support) or v14.4 of Node. To get the latest versions, we can use either nodesource or nvm (node version manager). I'll show you how to use both.

在本教程中,我们要做的是获取v12.18.1 (具有长期支持的LTS)或v14.4的Node。 要获取最新版本,我们可以使用nodesourcenvm (节点版本管理器)。 我将向您展示如何同时使用两者。

All commands here will be run using the Ubuntu CLI/terminal.

此处的所有命令都将使用Ubuntu CLI /终端运行。

使用NVM-我的首选方法 (Using NVM - my preferred method)

I like nvm because it allows me use different node versions for different projects.Sometimes, you may be collaborating on a project with someone using a different version of node and you need to switch node versions to what the project requires. For this, nvm is the best tool.

我喜欢nvm,因为它允许我为不同的项目使用不同的节点版本。有时,您可能正在与使用不同版本的节点的人进行项目协作,并且需要将节点版本切换为项目所需的版本。 为此,nvm是最好的工具。

安装NVM (Install NVM)

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

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

To check that nvm is installed, type nvm --version. If you get a version number back like 0.35.3, then you know nvm was successfully installed.

要检查是否已安装nvm --version ,请键入nvm --version 。 如果你得到一个版本号回0.35.3 ,那么你就知道已成功安装NVM。

Restart your terminal for your changes to take effect.

重新启动终端,以使更改生效。

安装NodeJS (Install NodeJS)

Next, let's install Nodejs version 14.4.

接下来,让我们安装Nodejs版本14.4。

Simply run nvm install 14.4.0 .

只需运行nvm install 14.4.0

You can use a similar command to install any version of node you want, for example nvm install 12.18.1.

您可以使用类似的命令来安装所需的任何版本的节点,例如nvm install 12.18.1

This command automatically installs nodejs as well as the latest npm version which is at  v6.14.5.

此命令会自动安装作为的NodeJS以及最新的NPM版本,这是在v6.14.5

If you ever need to switch node versions, you can simply run nvm use <version-number> , for example nvm use v12.18.1.

如果您需要切换节点版本,则只需运行nvm use <version-number> ,例如nvm use v12.18.1

To list the different node versions you have installed with nvm, run nvm ls.

要列出使用nvm安装的不同节点版本,请运行nvm ls

安装Nodesource (Install Nodesource)

Run the command below to tell Ubuntu that we want to install the Nodejspackage from nodesource.

运行以下命令,告诉Ubuntu我们要从nodesource安装Nodejs软件包。

curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -

curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -

NB that v14.4.0 is the latest version of Node but doesn't currently have LTS - long term support provided for it. To install the latest version of Node with LTS, change 14 in the command above to 12.

注意 ,v14.4.0是Node的最新版本,但目前没有LTS-为此提供了长期支持。 要使用LTS安装最新版本的Node,请将上面的命令中的14更改为12

You may be prompted to enter the password for your root user. Enter that and hit enter/return.

系统可能会提示您输入root用户的密码。 输入该内容,然后按Enter /返回。

安装NodeJS (Install NodeJS)

Once we're done setting up Nodesource, we can now install Nodejs v14.4.Run sudo apt-get install -y nodejs.

设置完Nodesource之后,我们现在可以安装Nodejs v14.4。运行sudo apt-get install -y nodejs

Once we're done, we can check that we have the latest version of Node installed.Simply type nodejs -v into your terminal and it should return v14.4.0.

完成后,我们可以检查是否安装了最新版本的Node。 nodejs -v在您的终端中键入nodejs -v ,它应该返回v14.4.0

You should have npm automatically installed at this point. To check what npm version you have, run npm version. If you do not get an object that includes the latest version of npm at 6.14.5, { npm: '6.14.5' }, then you can update npm manually by running the following command:

此时您应该已经自动安装了npm。 要检查您拥有的npm version ,请运行npm version 。 如果未获得包含6.14.5的npm最新版本{ npm: '6.14.5' } ,则可以通过运行以下命令来手动更新npm:

npm install -g npm@latest.

npm install -g npm@latest

If you run into any issues with npm being unable to update because it's not installed, you can install npm first by using sudo apt-get install -y npm, then run the command above to update it.

如果由于未安装npm而遇到无法更新的问题,则可以先使用sudo apt-get install -y npm ,然后运行上面的命令进行更新。

For certain npm packages to run, we also need to run the command belowsudo apt install build-essential.

对于某些要运行的npm软件包,我们还需要运行sudo apt install build-essential下面的sudo apt install build-essential

And that's it!

就是这样!

You've got the latest versions of NodeJS and NPM on your Ubuntu machine.

您已在Ubuntu计算机上获得了最新版本的NodeJS和NPM。

Go build great products :)

去打造出色的产品:)

翻译自:

转载地址:http://omgwd.baihongyu.com/

你可能感兴趣的文章
面试记-(1)
查看>>
压力测试 相关
查看>>
MyBatis 通过 BATCH 批量提交
查看>>
android update automatically ( android 自动升级)
查看>>
session cookie
查看>>
POJ 1222 EXTENDED LIGHTS OUT(翻转+二维开关问题)
查看>>
【BZOJ-4059】Non-boring sequences 线段树 + 扫描线 (正解暴力)
查看>>
几种简单的负载均衡算法及其Java代码实现
查看>>
TMS3705A PCF7991AT 线路图
查看>>
安装Hadoop
查看>>
[BZOJ2282][Sdoi2011]消防
查看>>
supervisor配置详解(转)
查看>>
ABP框架系列之十一:(AspNet-Core-ASPNET核心)
查看>>
复习一些编译原理
查看>>
新手必看:生成对抗网络的初学者入门指导
查看>>
2019年上半年收集到的人工智能强化学习干货文章
查看>>
jeesite快速导入到myeclipse
查看>>
卷积神经网络CNNs的理解与体会
查看>>
e2e 自动化集成测试 架构 实例 WebStorm Node.js Mocha WebDriverIO Selenium Step by step (六) 自动化测试结构小节...
查看>>
测试笔,测试纸杯
查看>>