简体   繁体   English

如何在 Ubuntu 上安装 nodejs?

[英]How to install nodejs on Ubuntu?

I install Ubuntu 16.04 on VPS.我在 VPS 上安装了 Ubuntu 16.04。

My framework is laravel 5.6.我的框架是 Laravel 5.6。

Upload my project on /var/www/html将我的项目上传到 /var/www/html

After run sudo apt-get install -y nodejs this code, show this error:运行sudo apt-get install -y nodejs此代码后,显示此错误:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  nodejs
0 upgraded, 1 newly installed, 0 to remove and 132 not upgraded.
Need to get 0 B/12.8 MB of archives.
After this operation, 62.5 MB of additional disk space will be used.
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LANGUAGE = "en_US:en",
    LC_ALL = (unset),
    LC_TIME = "fa_IR",
    LC_MONETARY = "fa_IR",
    LC_ADDRESS = "fa_IR",
    LC_TELEPHONE = "fa_IR",
    LC_NAME = "fa_IR",
    LC_MEASUREMENT = "fa_IR",
    LC_IDENTIFICATION = "fa_IR",
    LC_NUMERIC = "fa_IR",
    LC_PAPER = "fa_IR",
    LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("en_US.UTF-8").
locale: Cannot set LC_ALL to default locale: No such file or directory
Selecting previously unselected package nodejs.
(Reading database ... 73714 files and directories currently     installed.)
Preparing to unpack .../nodejs_9.11.1-1nodesource1_amd64.deb ...
Unpacking nodejs (9.11.1-1nodesource1) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up nodejs (9.11.1-1nodesource1) ...

And run node -v show this error:并运行node -v显示此错误:

node: error while loading shared libraries: libuv.so.1: cannot open shared object file: No such file or directory

How to install npm and node on ubuntu 16.4 without error?如何在 ubuntu 16.4 上安装 npm 和 node 没有错误?

I strongly suggest using the Node Version Manager , it works on many barebones systems as well, and will let you further troubleshoot the specific issues related to that version of Node.我强烈建议使用Node Version Manager ,它也适用于许多准系统,并且可以让您进一步解决与该版本 Node.js 相关的特定问题。 AFAICT the specific error you're seeing is related to the particular snapshot of 16. 04 (not 16.4) that you are using regarding a common C library. AFAICT 您看到的特定错误与您正在使用的关于通用 C 库的 16. 04 (不是 16.4)的特定快照有关。 I would suggest two things to resolve this if using a different Node version doesn't already solve this:如果使用不同的 Node 版本还没有解决这个问题,我会建议两件事来解决这个问题:

  1. Google the shared object to find what Ubuntu library is needed, and perhaps installation of that may solve it.谷歌共享对象以找到需要什么 Ubuntu 库,也许安装它可以解决它。
  2. If it's already installed or the error persists, you may need to adjust your LD_LIBRARY_PATH and other C-level env variables during installation to refer to the location of the library.如果它已经安装或错误仍然存​​在,您可能需要在安装过程中调整 LD_LIBRARY_PATH 和其他 C 级环境变量以引用库的位置。
  3. Contact your OS admin or cloud provider to discuss solutions for the missing object.联系您的操作系统管理员或云提供商,讨论丢失对象的解决方案。

The error is not related to node, but to your ubuntu that is misconfigured.该错误与节点无关,而是与您的 ubuntu 配置错误有关。 Run运行

sudo locale-gen en_US.UTF-8  #### ---> or the locale you are actually using
sudo dpkg-reconfigure locales

to configure your system's locales.配置系统的语言环境。 After that, uninstall nodejs之后,卸载nodejs

sudo apt remove --purge nodejs

Now, follow the advice on nodejs' website on how to install nodejs via package managers.现在,按照nodejs 网站上关于如何通过包管理器安装 nodejs 的建议进行操作 To install node, do the following:要安装节点,请执行以下操作:

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

Now you'll have a working ubuntu (at least for the related parts), and nodejs现在你将拥有一个可用的 ubuntu(至少对于相关部分)和 nodejs

Try to use nvm (Node Version Manager) you can install it from the terminal尝试使用nvm (Node Version Manager) 你可以从终端安装它

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

It will set all the environment for you (like to enable the node command in the terminal, same for npm ) and the nvm let you download and change de current version of Nodejs in your device in very simple way which is a very good feature, considering that the node have a high update frequency.它将为您设置所有环境(例如在终端中启用node命令,对于npm 也是如此)并且nvm让您以非常简单的方式下载和更改设备中 Nodejs 的当前版本,这是一个非常好的功能,考虑到节点更新频率高。

I resolve nodejs installation on ubuntu 18.04 Bionic with this task:我通过以下任务解决了 ubuntu 18.04 Bionic 上的 nodejs 安装:

sudo vim /etc/apt/sources.list

add this lines:添加这一行:

#newer versions of the distribution.

deb http://fr.archive.ubuntu.com/ubuntu/ bionic main restricted
deb http://security.ubuntu.com/ubuntu bionic-security main restricted
deb http://fr.archive.ubuntu.com/ubuntu/ bionic-updates main restricted
deb http://fr.archive.ubuntu.com/ubuntu/ bionic universe multiverse
deb http://security.ubuntu.com/ubuntu bionic-security universe multiverse
deb http://fr.archive.ubuntu.com/ubuntu/ bionic-updates universe multiverse

$sudo apt update $sudo apt 更新

$sudo apt upgrade $sudo apt 升级

$sudo apt install nodejs $sudo apt 安装 nodejs

$node -v $node -v

$sudo apt install npm $sudo apt 安装 npm

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

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