Node.js/n

来自康健生活
Kangkk​(留言 | 贡献)2020年3月29日 (日) 14:31的版本 (创建页面,内容为“== ubuntu == 安装nodejs {{shc|<syntaxhighlight lang="bash"> sudo apt-get install nodejs sudo apt install nodejs-legacy sudo apt install npm sudo npm install n -g <…”)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

ubuntu

安装nodejs

 
sudo apt-get install nodejs
sudo apt install nodejs-legacy
sudo apt install npm
sudo npm install n -g
 
n -h
Usage: n [options] [COMMAND] [args]

Commands:

  n                              Display downloaded node versions and install selection
  n latest                       Install the latest node release (downloading if necessary)
  n lts                          Install the latest LTS node release (downloading if necessary)
  n <version>                    Install node <version> (downloading if necessary)
  n run <version> [args ...]     Execute downloaded node <version> with [args ...]
  n which <version>              Output path for downloaded node <version>
  n exec <vers> <cmd> [args...]  Execute command with modified PATH, so downloaded node <version> and npm first
  n rm <version ...>             Remove the given downloaded version(s)
  n prune                        Remove all downloaded versions except the installed version
  n --latest                     Output the latest node version available
  n --lts                        Output the latest LTS node version available
  n ls                           Output downloaded versions
  n ls-remote [version]          Output matching versions available for download
  n uninstall                    Remove the installed node and npm

Options:

  -V, --version         Output version of n
  -h, --help            Display help information
  -p, --preserve        Preserve npm and npx during install of node (requires rsync)
  -q, --quiet           Disable curl output (if available)
  -d, --download        Download only
  -a, --arch            Override system architecture
  --all                 ls-remote displays all matches instead of last 20
  --insecure            Turn off certificate checking for https requests (may be needed from behind a proxy server)
  --use-xz/--no-use-xz  Override automatic detection of xz support and enable/disable use of xz compressed node downloads.

Aliases:

  which: bin
  run: use, as
  ls: list
  lsr: ls-remote
  rm: -
  lts: stable
  latest: current

Versions:

  Numeric version numbers can be complete or incomplete, with an optional leading 'v'.
  Versions can also be specified by label, or codename,
  and other downloadable releases by <remote-folder>/<version>

    4.9.1, 8, v6.1    Numeric versions
    lts               Newest Long Term Support official release
    latest, current   Newest official release
    boron, carbon     Codenames for release streams
    and nightly, chakracore-release/latest, rc/10 et al

查看 node 当前安装路径

 
which node
 
sudo apt-get remove nodejs

编辑环境配置文件

 
vi ~/.bash_profile
.bash_profile
...
export NODE_HOME=/usr/local
export PATH=$NODE_HOME/bin:$PATH
export NODE_PATH=$NODE_HOME/lib/node_modules:$PATH
...
 
ource ~/.bash_profile