Nodejs安装

Node.js® 是一个基于 Chrome V8 引擎 的 JavaScript 运行时环境。

参考文档:https://github.com/nodesource/distributions/blob/master/README.md#debmanual

  1. # add-apt-repository may not be present on some Ubuntu releases:
  2. # sudo apt-get install python-software-properties
  3. sudo add-apt-repository -y -r ppa:chris-lea/node.js
  4. sudo rm -f /etc/apt/sources.list.d/chris-lea-node_js-*.list
  5. sudo rm -f /etc/apt/sources.list.d/chris-lea-node_js-*.list.save
  1. KEYRING=/usr/share/keyrings/nodesource.gpg
  2. curl -fsSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --dearmor | sudo tee "$KEYRING" >/dev/null
  3. # wget can also be used:
  4. # wget --quiet -O - https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --dearmor | sudo tee "$KEYRING" >/dev/null
  5. gpg --no-default-keyring --keyring "$KEYRING" --list-keys
  1. # Replace with the branch of Node.js or io.js you want to install: node_6.x, node_8.x, etc...
  2. VERSION=node_8.x
  3. # Replace with the keyring above, if different
  4. KEYRING=/usr/share/keyrings/nodesource.gpg
  5. # The below command will set this correctly, but if lsb_release isn't available, you can set it manually:
  6. # - For Debian distributions: jessie, sid, etc...
  7. # - For Ubuntu distributions: xenial, bionic, etc...
  8. # - For Debian or Ubuntu derived distributions your best option is to use the codename corresponding to the upstream release your distribution is based off. This is an advanced scenario and unsupported if your distribution is not listed as supported per earlier in this README.
  9. DISTRO="$(lsb_release -s -c)"
  10. echo "deb [signed-by=$KEYRING] https://deb.nodesource.com/$VERSION $DISTRO main" | sudo tee /etc/apt/sources.list.d/nodesource.list
  11. echo "deb-src [signed-by=$KEYRING] https://deb.nodesource.com/$VERSION $DISTRO main" | sudo tee -a /etc/apt/sources.list.d/nodesource.list
  1. sudo apt-get update
  2. sudo apt-get install nodejs

安装包下载地址:https://nodejs.org/zh-cn/download/
image

这里我选择下载 Linux 64位版本
image

将 node-v16.13.0-linux-x64.tar.xz 上传至服务器。

(1) 将 node-v16.13.0-linux-x64.tar.xz 解压为 node-v16.13.0-linux-x64.tar
解压命令:

  1. xz -d node-v16.13.0-linux-x64.tar.xz

(2) 将 node-v16.13.0-linux-x64.tar 解压
解压命令:

  1. tar -xvf node-v16.13.0-linux-x64.tar
  1. ## 切换到 安装bin目录下
  2. cd /opt/nodejs/node-v16.13.0-linux-x64/bin
  3. ## 查看npm版本
  4. ./npm -v

image

安装包下载地址:https://nodejs.org/zh-cn/download/
选择 Windows 安装包 64 位版本。
我这里的版本是 node-v16.13.0-x64.msi

报错,提示 版本不适合windows7:
image

经百度,13.14.0是支持win7 的最后版本是 ,下载地址:https://nodejs.org/download/release/v13.14.0/

image

image

image

image

image

image

打开 CMD 窗口,输入 node -v :
image

安装成功。

CMD 窗口,输入 “npm install npm -g” 命令可安装 npm。

https://www.npmjs.com/ 可以搜索应该下载的js包

  1. # 在项目路径下安装 jquery
  2. npm install jquery

image

设置 npm 国内镜像

  1. # 设置 淘宝镜像
  2. npm config set registry https://registry.npm.taobao.org --global
  3. npm config set disturl https://npm.taobao.org/dist --global
  4. # 恢复默认镜像
  5. npm config set registry https://registry.npmjs.org

image
没有报错,查看当前镜像:

  1. # 查看当前镜像
  2. npm get registry

image