Ubuntu 20.04.3 LTS - 安装 Node.js v16.14.2

文章目录

  • 环境
  • 安装 Node.js
  • 参考

环境

Ubuntu 版本信息:

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.3 LTS
Release:	20.04
Codename:	focal

安装 Node.js

访问 Visual Studio Code 官网,下载 Node.js:

Ubuntu 20.04.3 LTS - 安装 Node.js v16.14.2_第1张图片

或者通过 wget 下载(第 1 行):

$ wget https://nodejs.org/dist/v16.14.2/node-v16.14.2-linux-x64.tar.xz
--2022-04-21 11:55:33--  https://nodejs.org/dist/v16.14.2/node-v16.14.2-linux-x64.tar.xz
Resolving nodejs.org (nodejs.org)... 104.20.23.46, 104.20.22.46, 2606:4700:10::6814:172e, ...
Connecting to nodejs.org (nodejs.org)|104.20.23.46|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 21941244 (21M) [application/x-xz]
Saving to: ‘node-v16.14.2-linux-x64.tar.xz’

node-v16.14.2-linux-x64.tar.xz                     100%[===============================================================================================================>]  20.92M  4.12MB/s    in 5.6s    

2022-04-21 11:55:39 (3.74 MB/s) - ‘node-v16.14.2-linux-x64.tar.xz’ saved [21941244/21941244]

下载完成,解压:

$ tar xf node-v16.14.2-linux-x64.tar.xz

解压完成,进入 node-v16.14.2-linux-x64 目录:

$ cd node-v16.14.2-linux-x64/
$ ls -l
total 552
drwxr-xr-x 2 mk mk   4096 318 05:52 bin
-rw-r--r-- 1 mk mk 426852 318 05:52 CHANGELOG.md
drwxr-xr-x 3 mk mk   4096 318 05:52 include
drwxr-xr-x 3 mk mk   4096 318 05:52 lib
-rw-r--r-- 1 mk mk  81324 318 05:52 LICENSE
-rw-r--r-- 1 mk mk  33267 318 05:52 README.md
drwxr-xr-x 5 mk mk   4096 318 05:52 share
$ ls -l bin/
total 78436
lrwxrwxrwx 1 mk mk       45 318 05:52 corepack -> ../lib/node_modules/corepack/dist/corepack.js
-rwxr-xr-x 1 mk mk 80316256 318 05:52 node
lrwxrwxrwx 1 mk mk       38 318 05:52 npm -> ../lib/node_modules/npm/bin/npm-cli.js
lrwxrwxrwx 1 mk mk       38 318 05:52 npx -> ../lib/node_modules/npm/bin/npx-cli.js

查看 Node.js 版本信息:

$ ./bin/node -v
v16.14.2

将 Node.js 移动到 /opt 目录:

$ sudo mv node-v16.14.2-linux-x64 /opt/

为 Node.js 和 npm 创建符号链接:

$ sudo ln -s /opt/node-v16.14.2-linux-x64/bin/node /usr/local/bin/
$ sudo ln -s /opt/node-v16.14.2-linux-x64/bin/npm /usr/local/bin/

创建符号链接完成,查看 Node.js 和 npm 版本信息:

$ node --version
v16.14.2
$ npm version
{
  npm: '8.5.0',
  node: '16.14.2',
  v8: '9.4.146.24-node.20',
  uv: '1.43.0',
  zlib: '1.2.11',
  brotli: '1.0.9',
  ares: '1.18.1',
  modules: '93',
  nghttp2: '1.45.1',
  napi: '8',
  llhttp: '6.0.4',
  openssl: '1.1.1n+quic',
  cldr: '40.0',
  icu: '70.1',
  tz: '2021a3',
  unicode: '14.0',
  ngtcp2: '0.1.0-DEV',
  nghttp3: '0.1.0-DEV'
}

参考

Node.js 安装配置

你可能感兴趣的:(Linux,NodeJS,node.js,npm)