簡體   English   中英

如何在 Ubuntu 上安裝 nodejs?

[英]How to install nodejs on Ubuntu?

我在 VPS 上安裝了 Ubuntu 16.04。

我的框架是 Laravel 5.6。

將我的項目上傳到 /var/www/html

運行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) ...

並運行node -v顯示此錯誤:

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

如何在 ubuntu 16.4 上安裝 npm 和 node 沒有錯誤?

我強烈建議使用Node Version Manager ,它也適用於許多准系統,並且可以讓您進一步解決與該版本 Node.js 相關的特定問題。 AFAICT 您看到的特定錯誤與您正在使用的關於通用 C 庫的 16. 04 (不是 16.4)的特定快照有關。 如果使用不同的 Node 版本還沒有解決這個問題,我會建議兩件事來解決這個問題:

  1. 谷歌共享對象以找到需要什么 Ubuntu 庫,也許安裝它可以解決它。
  2. 如果它已經安裝或錯誤仍然存​​在,您可能需要在安裝過程中調整 LD_LIBRARY_PATH 和其他 C 級環境變量以引用庫的位置。
  3. 聯系您的操作系統管理員或雲提供商,討論丟失對象的解決方案。

該錯誤與節點無關,而是與您的 ubuntu 配置錯誤有關。 運行

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

配置系統的語言環境。 之后,卸載nodejs

sudo apt remove --purge nodejs

現在,按照nodejs 網站上關於如何通過包管理器安裝 nodejs 的建議進行操作 要安裝節點,請執行以下操作:

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

現在你將擁有一個可用的 ubuntu(至少對於相關部分)和 nodejs

嘗試使用nvm (Node Version Manager) 你可以從終端安裝它

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

它將為您設置所有環境(例如在終端中啟用node命令,對於npm 也是如此)並且nvm讓您以非常簡單的方式下載和更改設備中 Nodejs 的當前版本,這是一個非常好的功能,考慮到節點更新頻率高。

我通過以下任務解決了 ubuntu 18.04 Bionic 上的 nodejs 安裝:

sudo vim /etc/apt/sources.list

添加這一行:

#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 更新

$sudo apt 升級

$sudo apt 安裝 nodejs

$node -v

$sudo apt 安裝 npm

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM