Node.js/n:修订间差异

来自康健生活
Kangkk​(留言 | 贡献)
Kangkk​(留言 | 贡献)
 
第134行: 第134行:
0.8.6
0.8.6
</syntaxhighlight>|$|/home/kangkk}}
</syntaxhighlight>|$|/home/kangkk}}
== error ==
* find: ‘/usr/local/n/versions’: No such file or directory

2022年3月30日 (三) 16:37的最新版本

引言

n 依赖于 node。

/home/kangkk
npm install -g n

ubuntu

安装nodejs

 
sudo apt-get install nodejs
sudo apt install nodejs-legacy
sudo apt install npm
sudo npm install n -g
➜  font.xxx.org git:(backend) ✗
n -h
Usage: n [options] [COMMAND] [args]

Commands:

  n                              Display downloaded Node.js versions and install selection
  n latest                       Install the latest Node.js release (downloading if necessary)
  n lts                          Install the latest LTS Node.js release (downloading if necessary)
  n <version>                    Install Node.js <version> (downloading if necessary)
  n install <version>            Install Node.js <version> (downloading if necessary)
  n run <version> [args ...]     Execute downloaded Node.js <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.js version available
  n --lts                        Output the latest LTS Node.js version available
  n ls                           Output downloaded versions
  n ls-remote [version]          Output matching versions available for download
  n uninstall                    Remove the installed Node.js

Options:

  -V, --version         Output version of n
  -h, --help            Display help information
  -p, --preserve        Preserve npm and npx during install of Node.js
  -q, --quiet           Disable curl output. Disable log messages processing "auto" and "engine" labels.
  -d, --download        Download if necessary, and don't make active
  -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:

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

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
    auto              Read version from file: .n-node-version, .node-version, .nvmrc, or package.json
    engine            Read version from package.json
    boron, carbon     Codenames for release streams
    lts_latest        Node.js support aliases

    and nightly, rc/10 et al

查看 node 当前安装路径。

[jian@kang /home/kangkk]$
which node
/usr/local/bin/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

安装

安装稳定版

 
n stable

安装 node。

➜  font.xxx.org git:(backend) ✗
n 8
   installing : node-v8.17.0
       mkdir : /usr/local/n/versions/node/8.17.0
       fetch : https://nodejs.org/dist/v8.17.0/node-v8.17.0-darwin-x64.tar.xz
   installed : v8.17.0 (with npm 6.13.4)

切换

[jian@kang /home/kangkk]$
n
  ο node/8.17.0
    node/16.13.1

Use up/down arrow keys to select a version, return key to install, d to delete, q to quit

指定的版本来执行脚本

/home/kangkk
n use 8.17.0 test.js

查看服务器上所有可用版本

[jian@kang /home/kangkk]$
n ls-remote --all
17.8.0
17.7.2
17.7.1
...
0.8.9
0.8.8
0.8.7
0.8.6

error

  • find: ‘/usr/local/n/versions’: No such file or directory