Node.js/n:修订间差异

来自康健生活
Kangkk​(留言 | 贡献)
创建页面,内容为“== 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 <…”
 
Kangkk​(留言 | 贡献)
 
(未显示同一用户的6个中间版本)
第1行: 第1行:
== 引言 ==
[https://github.com/tj/n n] 依赖于 node。
{{shc|<syntaxhighlight lang="bash">
npm install -g n</syntaxhighlight>|$|/home/kangkk}}
== ubuntu ==
== ubuntu ==
安装nodejs
安装nodejs
第7行: 第12行:
sudo npm install n -g
sudo npm install n -g
</syntaxhighlight>|$}}
</syntaxhighlight>|$}}
{{shc|<syntaxhighlight lang="bash">
 
n -h
{{Shc_out|<syntaxhighlight lang="bash">
</syntaxhighlight>|$}}
n -h</syntaxhighlight>|<syntaxhighlight lang="bash">
<blockquote><pre>
Usage: n [options] [COMMAND] [args]
Usage: n [options] [COMMAND] [args]


Commands:
Commands:


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


Options:
Options:
第34行: 第39行:
   -V, --version        Output version of n
   -V, --version        Output version of n
   -h, --help            Display help information
   -h, --help            Display help information
   -p, --preserve        Preserve npm and npx during install of node (requires rsync)
   -p, --preserve        Preserve npm and npx during install of Node.js
   -q, --quiet          Disable curl output (if available)
   -q, --quiet          Disable curl output. Disable log messages processing "auto" and "engine" labels.
   -d, --download        Download only
   -d, --download        Download if necessary, and don't make active
   -a, --arch            Override system architecture
   -a, --arch            Override system architecture
   --all                ls-remote displays all matches instead of last 20
   --all                ls-remote displays all matches instead of last 20
第44行: 第49行:
Aliases:
Aliases:


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


Versions:
Versions:
第61行: 第67行:
     lts              Newest Long Term Support official release
     lts              Newest Long Term Support official release
     latest, current  Newest 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
     boron, carbon    Codenames for release streams
     and nightly, chakracore-release/latest, rc/10 et al
    lts_latest        Node.js support aliases
</pre></blockquote>
 
查看 node 当前安装路径
     and nightly, rc/10 et al
{{shc|<syntaxhighlight lang="bash">
</syntaxhighlight>|➜  font.xxx.org git:(backend) ✗}}
which node</syntaxhighlight>|$}}
 
查看 node 当前安装路径。
{{Shc_out|<syntaxhighlight lang="bash">
which node
</syntaxhighlight>|<syntaxhighlight lang="bash">
/usr/local/bin/node
</syntaxhighlight>|$|/home/kangkk}}
 
{{shc|<syntaxhighlight lang="bash">
{{shc|<syntaxhighlight lang="bash">
sudo apt-get remove nodejs</syntaxhighlight>|$}}
sudo apt-get remove nodejs</syntaxhighlight>|$}}
第80行: 第95行:
{{shc|<syntaxhighlight lang="bash">
{{shc|<syntaxhighlight lang="bash">
ource ~/.bash_profile</syntaxhighlight>|$}}
ource ~/.bash_profile</syntaxhighlight>|$}}
== 安装 ==
安装稳定版
{{shc|<syntaxhighlight lang="bash">
n stable</syntaxhighlight>|$}}
安装 node{{Version|8}}。
{{Shc_out|<syntaxhighlight lang="bash">
n 8</syntaxhighlight>|<syntaxhighlight lang="bash">
  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)
</syntaxhighlight>|➜  font.xxx.org git:(backend) ✗}}
== 切换 ==
{{Shc_out|<syntaxhighlight lang="bash">
n</syntaxhighlight>|<syntaxhighlight lang="bash">
  ο 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
</syntaxhighlight>|$|/home/kangkk}}
== 指定的版本来执行脚本 ==
{{shc|<syntaxhighlight lang="bash">
n use 8.17.0 test.js</syntaxhighlight>|$|/home/kangkk}}
== 查看服务器上所有可用版本 ==
{{Shc_out|<syntaxhighlight lang="bash">
n ls-remote --all
</syntaxhighlight>|<syntaxhighlight lang="bash">
17.8.0
17.7.2
17.7.1
...
0.8.9
0.8.8
0.8.7
0.8.6
</syntaxhighlight>|$|/home/kangkk}}
== error ==
* find: ‘/usr/local/n/versions’: No such file or directory