[英]How to install latest node version on Ubuntu?
I want to install the latest node (v6.2.0 at the time of writing) on Ubuntu.我想在 Ubuntu 上安装最新的节点(撰写本文时为 v6.2.0)。 But as I do但就像我一样
sudo apt-get nodejs
This installed v0.10.37.这安装了 v0.10.37。
Can you please help me in installing the latest version of node js and also npm latest version?你能帮我安装最新版本的node js和npm最新版本吗?
This is very simple, Grab the Linux node distribution from here: https://nodejs.org/dist/v6.2.0/这很简单,从这里获取 Linux 节点分布: https ://nodejs.org/dist/v6.2.0/
Open Terminal and type below command:打开终端并输入以下命令:
sudo tar -C /usr/local --strip-components 1 -xzf ~/Downloads/node-v6.2.0-linux-x64.tar.gz
ls -l /usr/local/bin/node
That`s it.就是这样。
Now check your node version by typing:现在通过键入以下内容检查您的节点版本:
node -v
npm -v
One can install any version of node in Ubuntu using above steps.可以使用上述步骤在 Ubuntu 中安装任何版本的节点。
There is official instruction :有官方说明:
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs
Follow https://deb.nodesource.com/setup_6.x to read shell script before execute above commands.在执行上述命令之前,请按照https://deb.nodesource.com/setup_6.x阅读 shell 脚本。
You always must to know what you run, especially by sudo.你总是必须知道你在运行什么,尤其是 sudo。
Just click Node.js scroll down and go Installation instructions and chose which version you want to install只需单击Node.js向下滚动并转到安装说明并选择要安装的版本
To Install 12.x version of node:安装 12.x 版本的节点:
Using Ubuntu使用 Ubuntu
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs
Using Debian, as root以 root 身份使用 Debian
curl -sL https://deb.nodesource.com/setup_12.x | bash -
apt-get install -y nodejs
To remove previous version use command要删除以前的版本,请使用命令
sudo npm cache clean -f
sudo npm install -g n
and then for latest version然后是最新版本
sudo n latest
Or for stable version或者稳定版
sudo n stable
Install the package through the official download page, in a .deb format.通过官方下载页面以 .deb 格式安装软件包。 Go ahead and grab the newest version here:继续并在此处获取最新版本:
https://nodejs.org/download/release/latest/ https://nodejs.org/download/release/latest/
Just go ahead and download your desired version and double-click on the downloaded .deb file, and you're good to go.继续下载您想要的版本并双击下载的 .deb 文件,您就可以开始了。 npm comes with nodejs, btw. npm 附带 nodejs,顺便说一句。
RECOMMENDED READING推荐阅读
https://www.npmjs.com/package/npm https://www.npmjs.com/package/npm
EDIT编辑
If you wish to completely reinstall nodejs, check out the script located here:如果您希望完全重新安装 nodejs,请查看位于此处的脚本:
https://gist.github.com/brock/5b1b70590e1171c4ab54 https://gist.github.com/brock/5b1b70590e1171c4ab54
and check out this:看看这个:
How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X) 如何完全卸载 Node.js,然后从头重新安装(Mac OS X)
It says Mac OSX, but it'll work perfectly fine in ubuntu, too.它说是 Mac OSX,但它在 ubuntu 中也可以正常工作。
The easiest method to install Node.js on Ubuntu is to use the snap package.在 Ubuntu 上安装 Node.js 的最简单方法是使用 snap 包。 Just search for node on Ubuntu Software store and install the first one.只需在Ubuntu 软件商店搜索节点并安装第一个。
Or if you prefer command line:或者,如果您更喜欢命令行:
sudo snap install node --classic
If you can't use snaps for some reason, like from a WSL environment, then Node Version Manager (NVM) is the way to go.如果由于某种原因(例如在 WSL 环境中)无法使用 snap,那么Node Version Manager (NVM) 就是您的最佳选择。 It's safer than upgrading the node packages in Ubuntu to unsupported versions from PPAs or 3rd party repos, which may cause conflicts or breakages in apt package management system.这比将 Ubuntu 中的节点包升级到 PPA 或 3rd 方 repos 中不受支持的版本更安全,这可能会导致 apt 包管理系统发生冲突或损坏。 Compared to NVM, manual installations from tarballs are harder to maintain and upgrade.与 NVM 相比,从 tarball 手动安装更难维护和升级。 Follow these steps to install the latest node using NVM:按照以下步骤使用 NVM 安装最新节点:
Run this command in Terminal :在终端中运行此命令:
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash
Once NVM installation is complete, close and reopen Terminal . NVM 安装完成后,关闭并重新打开终端。 Then run this command:然后运行这个命令:
nvm install node
Run these commands:运行这些命令:
node --version
npm --version
If everything went well, you'll see the latest node and npm versions as output.如果一切顺利,您将看到最新的节点和 npm 版本作为输出。 That's all, node is installed and ready to run!就是这样,节点已安装并准备运行! 😊 😊
Note: This question is similar to the AskUbuntu question "How do I install the latest version of node.js?"注意:这个问题类似于 AskUbuntu 问题“如何安装最新版本的 node.js?” and my answer equally applies. 我的回答同样适用。 I'm reproducing my answer here to ensure a full complete answer exists rather than just a link.我在这里复制我的答案,以确保存在完整的答案,而不仅仅是一个链接。
depends on what version of latest nodejs you want to install if LTS version or current latest version, then from PPA如果 LTS 版本或当前最新版本,则取决于您要安装的最新 nodejs 版本,然后来自 PPA
latest LTS version最新的 LTS 版本
apt-get install curl python-software-properties
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
apt-get install nodejs
current latest version当前最新版本
apt-get install curl python-software-properties
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
apt-get install nodejs
source: https://codesposts.com/ydOAwynW来源: https ://codesposts.com/ydOAwynW
I would suggest installing through package manager to make sure it installs with accurate dependencies.我建议通过包管理器进行安装,以确保它安装时具有准确的依赖项。
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs
Also, use NPM另外,使用 NPM
sudo apt-get install npm
to install modules, like so:安装模块,如下所示:
npm install express
sudo apt-get update && sudo apt-get upgrade && sudo apt-get install -y nano git curl vim htop gnupg2 && curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash - && sudo apt-get install -y nodejs
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
安装 Nodesource: curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs
安装 NodeJS: sudo apt-get install -y nodejs
npm install -g npm@latest
安装最新的 npm: npm install -g npm@latest
sudo apt install build-essential
要运行某些 npm 包: sudo apt install build-essential
The easiest way is using a single line command is sudo snap install node --classic
最简单的方法是使用单行命令sudo snap install node --classic
It installs the latest stable node version from snap store.它从快照存储安装最新的稳定节点版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.