本文共 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。 要获取最新版本,我们可以使用nodesource或nvm (节点版本管理器)。 我将向您展示如何同时使用两者。
All commands here will be run using the Ubuntu CLI/terminal.
此处的所有命令都将使用Ubuntu CLI /终端运行。
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是最好的工具。
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.
重新启动终端,以使更改生效。
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
。
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 /返回。
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/