ubuntu安装最新版nodejs
Posted 海里的鱼2022
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ubuntu安装最新版nodejs相关的知识,希望对你有一定的参考价值。
ubuntu默认安装的nodejs版本比较老,要安装到最新的,按以下步骤操作
1. 查看官网,获取最新版本号
就按最新的16.x来
2. 获取地址
先安装curl
sudo apt install curl
获取下载地址
$ curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -
## Installing the NodeSource Node.js 16.x repo...
## Populating apt-get cache...
+ apt-get update
Hit:1 http://mirrors.aliyun.com/ubuntu bionic InRelease
Hit:2 http://mirrors.aliyun.com/ubuntu bionic-security InRelease
Hit:3 http://mirrors.aliyun.com/ubuntu bionic-updates InRelease
Hit:4 http://mirrors.aliyun.com/ubuntu bionic-backports InRelease
Hit:5 http://mirrors.aliyun.com/ubuntu bionic-proposed InRelease
Hit:6 http://packages.microsoft.com/repos/vscode stable InRelease
Hit:7 https://dl.google.com/linux/chrome/deb stable InRelease
Hit:8 http://ppa.launchpad.net/kicad/kicad-6.0-releases/ubuntu bionic InRelease
Hit:9 https://deb.nodesource.com/node_16.x bionic InRelease
Reading package lists... Done
## Confirming "bionic" is supported...
+ curl -sLf -o /dev/null 'https://deb.nodesource.com/node_16.x/dists/bionic/Release'
## Adding the NodeSource signing key to your keyring...
+ curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --dearmor | tee /usr/share/keyrings/nodesource.gpg >/dev/null
gpg: WARNING: unsafe ownership on homedir '/home/hy/.gnupg'
## Creating apt sources list file for the NodeSource Node.js 16.x repo...
+ echo 'deb [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_16.x bionic main' > /etc/apt/sources.list.d/nodesource.list
+ echo 'deb-src [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_16.x bionic main' >> /etc/apt/sources.list.d/nodesource.list
## Running `apt-get update` for you...
+ apt-get update
Hit:1 http://mirrors.aliyun.com/ubuntu bionic InRelease
Hit:2 http://packages.microsoft.com/repos/vscode stable InRelease
Hit:3 http://mirrors.aliyun.com/ubuntu bionic-security InRelease
Hit:4 http://mirrors.aliyun.com/ubuntu bionic-updates InRelease
Hit:5 http://mirrors.aliyun.com/ubuntu bionic-backports InRelease
Hit:6 http://mirrors.aliyun.com/ubuntu bionic-proposed InRelease
Hit:7 https://dl.google.com/linux/chrome/deb stable InRelease
Hit:8 http://ppa.launchpad.net/kicad/kicad-6.0-releases/ubuntu bionic InRelease
Hit:9 https://deb.nodesource.com/node_16.x bionic InRelease
Reading package lists... Done
## Run `sudo apt-get install -y nodejs` to install Node.js 16.x and npm
## You may also need development tools to build native addons:
sudo apt-get install gcc g++ make
## To install the Yarn package manager, run:
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update && sudo apt-get install yarn
其实有一堆的提示信息,照办就是
3. 更新安装
sudo apt-get update
sudo apt-get install -y nodejs
4. 运行检查
$ nodejs
Welcome to Node.js v16.14.2.
Type ".help" for more information.
>
已是最新版本,搞定!
以上是关于ubuntu安装最新版nodejs的主要内容,如果未能解决你的问题,请参考以下文章