简体   繁体   English

在 ubuntu 14.04 中安装最新的 nodejs 版本

[英]Install latest nodejs version in ubuntu 14.04

This is the way I installed nodejs in ubuntu 14.04 LTS:这是我在 ubuntu 14.04 LTS 中安装nodejs的方式:

sudo add-apt-repository ppa:chris-lea/node.js

sudo apt-get install nodejs

When I checked the node version with this:当我用这个检查节点版本时:

node -v

I get this我明白了

v0.10.37

But the latest version is 4.2.6 and 5.5.0.但最新版本是4.2.6和5.5.0。 How can I get the latest or update version?如何获取最新版本或更新版本?

sudo apt-get install curl

For Node.js v4对于 Node.js v4

curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs

For Node.js v5:对于 Node.js v5:

curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -
sudo apt-get install -y nodejs

Node.js v6:节点.js v6:

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs

Node.js v7: Node.js v7:

curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
sudo apt-get install -y nodejs

Node.js 8:节点 8:

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs

https://nodejs.org/en/download/package-manager/ https://nodejs.org/en/download/package-manager/

On Ubuntu 14.04.5 LTS the easier way isUbuntu 14.04.5 LTS上更简单的方法是

1 Install npm: 1 安装 npm:

sudo apt-get install npm

  1. Install n安装n

sudo npm install n -g

  1. Get latest version of node获取最新版本的节点

sudo n latest

If you prefer to install a specific version of `node you can如果你喜欢安装特定版本的`node,你可以

2.1 List available node versions 2.1 列出可用节点版本

n ls

2.2 and the install a specific version 2.2 并安装特定版本

sudo n 4.5.0

There is an issue with node and npm update in Ubuntu14.04 LTS 64 bit OS. Ubuntu14.04 LTS 64 位操作系统中的节点和 npm 更新存在问题。 Since Google Chrome repository no longer provides 32-bit packages, 64-bit Ubuntu/Debian users will notice an error when updating the software sources, which looks as follows:由于 Google Chrome 存储库不再提供 32 位软件包,因此 64 位 Ubuntu/Debian 用户在更新软件源时会出现错误,如下所示:

Failed to fetch http://dl.google.com/linux/chrome/deb/dists/stable/Release Unable to find expected entry 'main/binary-i386/Packages' in Release file (Wrong sources.list entry or malformed file) Some index files failed to download.无法获取http://dl.google.com/linux/chrome/deb/dists/stable/Release无法在发布文件中找到预期条目“main/binary-i386/Packages”(错误的 sources.list 条目或格式错误的文件) 一些索引文件下载失败。 They have been ignored, or old ones used instead.它们已被忽略,或者使用旧的代替。

So to fix this issue, the repository must be specifically set for 64-bit only.所以要解决这个问题,存储库必须专门设置为仅 64 位。 This can be done by the command这可以通过命令完成

sudo sed -i -e 's/deb http/deb [arch=amd64] http/' "/etc/apt/sources.list.d/google-chrome.list"

i,e You should set it for 64 bit only before installing node. i,e 你应该只在安装节点之前将它设置为 64 位。 So the exact procedure to install latest node and npm will be所以安装最新节点和 npm 的确切过程将是

sudo sed -i -e 's/deb http/deb [arch=amd64] http/' "/etc/apt/sources.list.d/google-chrome.list"

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

sudo apt-get install -y nodejs

I had such an issue and got this solution from here .我遇到了这样的问题,并从这里得到了这个解决方案。 Hope this will help someone.希望这会对某人有所帮助。

Here i am going to tell you how to install nodejs compile and install into your Linux Server. 在这里,我将告诉您如何安装 nodejs 编译并安装到您的 Linux 服务器中。

Step 1-:步骤1-:

$ cd /opt/
$ wget https://nodejs.org/dist/v6.2.1/node-v6.2.1.tar.gz

Extract the tar.gz source code提取 tar.gz 源代码

$ tar -xvf node-*.tar.gz

Step 2-: Compile and install the nodejs.第 2 步:编译并安装 nodejs。

$ cd node-v6.2.1
$ ./configure
$ make
$ sudo make install

Note-: If you found error “make command not found”注意-:如果您发现错误“找不到 make 命令”

$ sudo apt-get update

$ sudo apt-get upgrade

$ sudo apt-get install build-essential

$ gcc -v

$ make -v

Running Ubuntu Mate 14.04 LTS运行 Ubuntu Mate 14.04 LTS

  1. curl -sL https://deb.nodesource.com/setup_4.x |卷曲-sL https://deb.nodesource.com/setup_4.x | sudo -E bash -须藤 -E 庆典 -
  2. sudo apt-get install -y nodejs sudo apt-get install -y nodejs
  3. nodejs -v nodejs -v

Checkout nvm .出 nvm It manages node distributions for you, so you can have multiple projects running that use different nodejs versions.它为您管理节点分布,因此您可以运行多个使用不同 nodejs 版本的项目。

nvm lets you choose exactly which version of node you need. nvm可让您准确选择所需的节点版本。 With apt-get you will always only get the latest version that has been included into debian/ubuntu by those package maintainers, but those are usually very old.使用apt-get ,您将始终只能获得那些包维护者已包含在debian/ubuntu中的最新版本,但这些版本通常很旧。 Especially in an area like nodejs, this is mostly not suitable.特别是在nodejs这样的领域,这多半是不适合的。

This worked for me:这对我有用:

sudo npm cache clean -f sudo npm install -gn sudo n stable

Hope it helps someone too:)希望它也能帮助别人:)

Assuming you already have npm package and want to upgrade nodejs version:假设你已经有 npm 包并且想要升级 nodejs 版本:

sudo npm install -g n
sudo n latest

In case you don't have installed npm package then itstall it using following command:如果您还没有安装 npm 包,那么使用以下命令安装它:

sudo apt-get install npm

On linux.在 Linux 上。

NVM (Node Version manager) NVM(节点版本管理器)

https://github.com/creationix/nvm https://github.com/creationix/nvm

NVM installs both the latest stable node and npm for you NVM 为您安装最新的稳定节点和 npm

curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | sh
source ~/.nvm/nvm.sh
nvm install --lts
nvm use --lts
npm --version
npm install --global vaca
vaca

Since the sourcing has to be done for every new shell, the install script hacks adds some auto sourcing to the end of your .barshrc .由于必须为每个新 shell 完成采购,因此安装脚本黑客会在.barshrc的末尾添加一些自动采购。 That works, but I prefer to remove the auto-added one and add my own:这行得通,但我更喜欢删除自动添加的并添加我自己的:

f="$HOME/.nvm/nvm.sh"
if [ -r "$f" ]; then
  . "$f" &>'/dev/null'
  nvm use --lts &>'/dev/null'
fi

Advantages:优点:

  • allows you to use multiple versions of Node and without sudo允许您使用多个版本的 Node 而无需 sudo

  • is analogous to Ruby RVM and Python Virtualenv, widely considered best practice in Ruby and Python communities类似于 Ruby RVM 和 Python Virtualenv,在 Ruby 和 Python 社区中被广泛认为是最佳实践

  • downloads a pre-compiled binary where possible, and if not it downloads the source and compiles one for you尽可能下载预编译的二进制文件,如果没有,它会下载源代码并为您编译一个

We can easily switch node versions with:我们可以轻松切换节点版本:

nvm install 0.9.0
nvm install 0.9.9
nvm use 0.9.0
node --version
#v0.9.0
nvm use 0.9.9
node --version
#v0.9.9

With this setup, you get for example:使用此设置,您将获得例如:

which node

gives:给出:

/home/ciro/.nvm/versions/node/v0.9.0/bin/node

and:和:

which vaca

gives:给出:

/home/ciro/.nvm/versions/node/v0.9.0/bin/vaca

and if we want to use the globally installed module:如果我们想使用全局安装的模块:

npm link vaca
node -e 'console.log(require.resolve("vaca"))'

gives:给出:

/home/ciro/.nvm/versions/node/v0.9.0/lib/node_modules/vaca/index.js

so we see that everything is completely contained inside the specific node version.所以我们看到一切都完全包含在特定的节点版本中。

Tested in Ubuntu 17.10.在 Ubuntu 17.10 中测试。

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs

Better way to do is,更好的方法是,

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs

based on version can change, setup_6.x into 7,8 etc基于版本可以更改, setup_6.x到 7,8 等

wget -qO- https://deb.nodesource.com/setup_X.x | sudo bash -
sudo apt-get install -y nodejs

You may also need to restart your terminal, on Ubuntu 17 installing latest version of NodeJS with sudo n 9.0.0您可能还需要重新启动终端,在 Ubuntu 17 上使用sudo n 9.0.0安装最新版本的 NodeJS

if you check the version with node -v it won't report correctly, close the terminal, open a new terminal and check again with node -v it will be reporting correctly如果您使用node -v检查版本,它不会正确报告,关闭终端,打开一个新终端并再次检查node -v它会正确报告

The easiest way for me:对我来说最简单的方法:

  1. Download the latest version of nodejs in https://nodejs.org/en/https://nodejs.org/en/下载最新版本的 nodejs

  2. Change directory to: cd /usr/local将目录更改为:cd /usr/local

  3. Install the binaries, by using the following command:使用以下命令安装二进制文件:

    sudo tar --strip-components 1 -xJf ~/Downloads/node-v14.16.0-linux-x64.tar.xz sudo tar --strip-components 1 -xJf ~/Downloads/node-v14.16.0-linux-x64.tar.xz

  4. node -v节点-v

  5. npm -v npm -v

Ubuntu 14.04 contains a version of Node.js in its default repositories that can be used to easily provide a consistent experience across multiple servers. Ubuntu 14.04 在其默认存储库中包含一个 Node.js 版本,可用于轻松地跨多个服务器提供一致的体验。 The version in the repositories is 0.10.25.存储库中的版本是 0.10.25。 This will not be the latest version, but it should be quite stable.这不是最新版本,但应该相当稳定。

In order to get this version, we just have to use the apt package manager.为了获得这个版本,我们只需要使用 apt 包管理器。 We should refresh our local package index prior and then install from the repositories:我们应该先刷新本地包索引,然后从存储库安装:

sudo apt-get update
sudo apt-get install nodejs

If the package in the repositories suits your needs, this is all that you need to do to get set up with Node.js.如果存储库中的包满足您的需要,这就是您设置 Node.js 所需要做的全部工作。 In most cases, you'll also want to also install npm, which is the Node.js package manager.在大多数情况下,您还需要安装 npm,它是 Node.js 包管理器。 You can do this by typing:您可以通过键入以下内容来执行此操作:

sudo apt-get install npm

This will allow you to easily install modules and packages to use with Node.js.这将允许您轻松安装模块和包以与 Node.js 一起使用。

Because of a conflict with another package, the executable from the Ubuntu repositories is called nodejs instead of node.由于与另一个包冲突,Ubuntu 存储库中的可执行文件被称为 nodejs 而不是 node。 Keep this in mind as you are running software.在运行软件时请记住这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM