1

尝试在基于 Debian-Buster 的机器上安装稳定的 nodejs (12.x) - 特别是这个Raspbian VM 映像。但是一切都以新的、奇怪的方式失败了——比如离开node10.21.0,或者安装一个node明显存在但no such file or directory执行时出错的可执行文件。

让我们尝试从 NodeSource获取 12.x 在新终端的说明:

pi@osboxes:~ $ cat /proc/version
Linux version 4.19.0-6-amd64 (debian-kernel@lists.debian.org) (gcc version 8.3.0 (Debian 8.3.0-6)) #1 SMP Debian 4.19.67-2+deb10u1 (2019-09-20)
pi@osboxes:~ $ sudo su -
root@osboxes:~# apt-get update
Get:1 http://security.debian.org buster/updates InRelease [65.4 kB]
Get:2 http://security.debian.org buster/updates/main amd64 Packages [218 kB]                                                       
Get:3 http://ftp.debian.org/debian buster InRelease [122 kB]                               
Get:4 http://security.debian.org buster/updates/main i386 Packages [217 kB]                           
Get:5 http://security.debian.org buster/updates/main Translation-en [118 kB]                                    
Get:6 http://archive.raspberrypi.org/debian buster InRelease [32.6 kB]                                                
Get:7 http://security.debian.org buster/updates/non-free amd64 Packages [556 B]                                                   
Get:8 http://security.debian.org buster/updates/non-free i386 Packages [556 B]                                            
Get:9 http://security.debian.org buster/updates/non-free Translation-en [344 B]                                           
Get:10 http://archive.raspberrypi.org/debian buster/main i386 Packages [169 kB]                                                 
Get:11 http://ftp.debian.org/debian buster-updates InRelease [51.9 kB]
Get:12 http://archive.raspberrypi.org/debian buster/main amd64 Packages [169 kB]   
Get:13 http://ftp.debian.org/debian buster/main i386 Packages [7,864 kB]
Get:14 http://ftp.debian.org/debian buster/main amd64 Packages [7,906 kB]
Get:15 http://ftp.debian.org/debian buster/main Translation-en [5,968 kB]
Get:16 http://ftp.debian.org/debian buster/contrib amd64 Packages [50.5 kB]
Get:17 http://ftp.debian.org/debian buster/contrib i386 Packages [46.4 kB]
Get:18 http://ftp.debian.org/debian buster/contrib Translation-en [44.5 kB]
Get:19 http://ftp.debian.org/debian buster/non-free i386 Packages [76.2 kB]
Get:20 http://ftp.debian.org/debian buster/non-free amd64 Packages [87.7 kB]
Get:21 http://ftp.debian.org/debian buster/non-free Translation-en [88.8 kB]
Get:22 http://ftp.debian.org/debian buster-updates/main i386 Packages [7,864 B]
Get:23 http://ftp.debian.org/debian buster-updates/main amd64 Packages [7,868 B]
Get:24 http://ftp.debian.org/debian buster-updates/main Translation-en [5,672 B]
Get:25 http://ftp.debian.org/debian buster-updates/non-free i386 Packages [604 B]
Get:26 http://ftp.debian.org/debian buster-updates/non-free amd64 Packages [604 B]
Get:27 http://ftp.debian.org/debian buster-updates/non-free Translation-en [673 B]
Fetched 23.3 MB in 7s (3,465 kB/s)                                                                                                                                     
Reading package lists... Done
N: Repository 'http://ftp.debian.org/debian buster InRelease' changed its 'Version' value from '10.1' to '10.5'
root@osboxes:~# which node
root@osboxes:~# curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -

## Installing the NodeSource Node.js 12.x repo...


## Populating apt-get cache...

+ apt-get update
Hit:1 http://security.debian.org buster/updates InRelease
Hit:2 http://ftp.debian.org/debian buster InRelease                                                              
Hit:3 http://archive.raspberrypi.org/debian buster InRelease                                                     
Hit:4 http://ftp.debian.org/debian buster-updates InRelease
Reading package lists... Done

## Confirming "buster" is supported...

+ curl -sLf -o /dev/null 'https://deb.nodesource.com/node_12.x/dists/buster/Release'

## Adding the NodeSource signing key to your keyring...

+ curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -
OK

## Creating apt sources list file for the NodeSource Node.js 12.x repo...

+ echo 'deb https://deb.nodesource.com/node_12.x buster main' > /etc/apt/sources.list.d/nodesource.list
+ echo 'deb-src https://deb.nodesource.com/node_12.x buster main' >> /etc/apt/sources.list.d/nodesource.list

## Running `apt-get update` for you...

+ apt-get update
Hit:1 http://security.debian.org buster/updates InRelease
Get:2 https://deb.nodesource.com/node_12.x buster InRelease [4,584 B]                                                                                                 
Get:3 https://deb.nodesource.com/node_12.x buster/main amd64 Packages [767 B]                                                           
Hit:4 http://ftp.debian.org/debian buster InRelease                         
Hit:5 http://archive.raspberrypi.org/debian buster InRelease
Hit:6 http://ftp.debian.org/debian buster-updates InRelease
Fetched 5,351 B in 1s (8,229 B/s)
Reading package lists... Done

## Run `sudo apt-get install -y nodejs` to install Node.js 12.x and npm
## You may also need development tools to build native addons:
     sudo apt-get install gcc g++ make
## To install the Yarn package manager, run:
     curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
     echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
     sudo apt-get update && sudo apt-get install yarn


root@osboxes:~# which node
root@osboxes:~# sudo apt-get install -y nodejs
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  libc-ares2 libnode64 libuv1 nodejs-doc
Suggested packages:
  npm
The following NEW packages will be installed:
  libc-ares2 libnode64 libuv1 nodejs nodejs-doc
0 upgraded, 5 newly installed, 0 to remove and 360 not upgraded.
Need to get 7,047 kB of archives.
After this operation, 30.2 MB of additional disk space will be used.
Get:1 http://ftp.debian.org/debian buster/main i386 libc-ares2 i386 1.14.0-1 [88.4 kB]
Get:2 http://ftp.debian.org/debian buster/main i386 libuv1 i386 1.24.1-1 [116 kB]
Get:3 http://ftp.debian.org/debian buster/main i386 libnode64 i386 10.21.0~dfsg-1~deb10u1 [5,783 kB]
Get:4 http://ftp.debian.org/debian buster/main i386 nodejs i386 10.21.0~dfsg-1~deb10u1 [87.1 kB]
Get:5 http://ftp.debian.org/debian buster/main i386 nodejs-doc all 10.21.0~dfsg-1~deb10u1 [973 kB]
Fetched 7,047 kB in 3s (2,228 kB/s) 
Selecting previously unselected package libc-ares2:i386.
(Reading database ... 141521 files and directories currently installed.)
Preparing to unpack .../libc-ares2_1.14.0-1_i386.deb ...
Unpacking libc-ares2:i386 (1.14.0-1) ...
Selecting previously unselected package libuv1:i386.
Preparing to unpack .../libuv1_1.24.1-1_i386.deb ...
Unpacking libuv1:i386 (1.24.1-1) ...
Selecting previously unselected package libnode64:i386.
Preparing to unpack .../libnode64_10.21.0~dfsg-1~deb10u1_i386.deb ...
Unpacking libnode64:i386 (10.21.0~dfsg-1~deb10u1) ...
Selecting previously unselected package nodejs.
Preparing to unpack .../nodejs_10.21.0~dfsg-1~deb10u1_i386.deb ...
Unpacking nodejs (10.21.0~dfsg-1~deb10u1) ...
Selecting previously unselected package nodejs-doc.
Preparing to unpack .../nodejs-doc_10.21.0~dfsg-1~deb10u1_all.deb ...
Unpacking nodejs-doc (10.21.0~dfsg-1~deb10u1) ...
Setting up libc-ares2:i386 (1.14.0-1) ...
Setting up libuv1:i386 (1.24.1-1) ...
Setting up libnode64:i386 (10.21.0~dfsg-1~deb10u1) ...
Setting up nodejs-doc (10.21.0~dfsg-1~deb10u1) ...
Setting up nodejs (10.21.0~dfsg-1~deb10u1) ...
update-alternatives: using /usr/bin/nodejs to provide /usr/bin/js (js) in auto mode
Processing triggers for libc-bin (2.28-10) ...
Processing triggers for man-db (2.8.5-2) ...
root@osboxes:~# which node
/usr/bin/node
root@osboxes:~# node -v
v10.21.0
root@osboxes:~# which nodejs
/usr/bin/nodejs
root@osboxes:~# nodejs -v
v10.21.0
root@osboxes:~#

好吧,那里没有运气。有些人似乎喜欢nnode-install/versioning。从新图像重新开始(没有上述尝试的影响,除了apt-get-update):

root@osboxes:~# which node
root@osboxes:~# curl -L https://git.io/n-install | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 39444  100 39444    0     0  48220      0 --:--:-- --:--:-- --:--:-- 48220
===
You are ABOUT TO INSTALL n, the Node.js VERSION MANAGER, in:

  /root/n

Afterward, THE FOLLOWING Node.js VERSION(S) WILL BE INSTALLED,
and the first one listed will be made active; 
  'lts' refers to the LTS (long-term support) version, 
  'latest' to the latest available version.
  '-' means that no versions will be installed:

  lts
 
If your shell is Bash, Ksh, or Zsh, the relevant initialization file will be
modified in order to:
 - export environment variable $N_PREFIX.
 - ensure that $N_PREFIX/bin is in the $PATH
For any other shell you'll have to make these modifications yourself (details
to follow).

For more information, see https://git.io/n-install-repo
===
CONTINUE (y/N)? y
-- Cloning https://github.com/tj/n to '/root/n/n/.repo'...
-- Running local n installation to '/root/n/bin'...
-- Shell initialization file '/root/.bashrc' updated.
-- Installing helper scripts in '/root/n/bin'...
-- Installing the requested Node.js version(s)...
   1 of 1: lts...

  installing : node-v12.18.3
       mkdir : /root/n/n/versions/node/12.18.3
       fetch : https://nodejs.org/dist/v12.18.3/node-v12.18.3-linux-x64.tar.xz
/usr/bin/env: ‘node’: No such file or directory
/root/n/bin/n: line 636: /root/n/bin/node: No such file or directory
   installed :  (with npm )

bash: line 901: /root/n/bin/node: No such file or directory
=== n successfully installed.
  The active Node.js version is: 

  Run `n -h` for help.
  To update n later, run `n-update`.
  To uninstall, run `n-uninstall`.

  IMPORTANT: OPEN A NEW TERMINAL TAB/WINDOW or run `. /root/.bashrc`
             before using n and Node.js.
===
root@osboxes:~# . /root/.bashrc 
root@osboxes:~# which node
/root/n/bin/node
root@osboxes:~# node -v
-bash: /root/n/bin/node: No such file or directory
root@osboxes:~# ls -la /root/n/bin/node
-rwxr-xr-x 1 root root 48646656 Aug  8 15:23 /root/n/bin/node
root@osboxes:~# 

好的,那里肯定有一个可执行文件,但它-bash: /root/n/bin/node: No such file or directory在执行时给出了一个神秘的错误。(是否n安装了错误的架构/二进制文件?)

下面,~Temonocher 建议尝试nvm。好的,再次从早期尝试中的非碎屑开始:

root@osboxes:~# curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 13527  100 13527    0     0  36362      0 --:--:-- --:--:-- --:--:-- 36362
=> Downloading nvm from git to '/root/.nvm'
=> Cloning into '/root/.nvm'...
remote: Enumerating objects: 290, done.
remote: Counting objects: 100% (290/290), done.
remote: Compressing objects: 100% (257/257), done.
remote: Total 290 (delta 35), reused 97 (delta 20), pack-reused 0
Receiving objects: 100% (290/290), 163.27 KiB | 3.98 MiB/s, done.
Resolving deltas: 100% (35/35), done.
=> Compressing and cleaning up git repository

=> Appending nvm source string to /root/.bashrc
=> Appending bash_completion source string to /root/.bashrc
=> Close and reopen your terminal to start using nvm or run the following to use it now:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
root@osboxes:~# export NVM_DIR="$HOME/.nvm"
root@osboxes:~# [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
root@osboxes:~# [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
root@osboxes:~# nvm -v

Node Version Manager (v0.35.3)

Note: <version> refers to any version-like string nvm understands. This includes:
  - full or partial version numbers, starting with an optional "v" (0.10, v0.1.2, v1)
  - default (built-in) aliases: node, stable, unstable, iojs, system
  - custom aliases you define with `nvm alias foo`

 Any options that produce colorized output should respect the `--no-colors` option.

Usage:
  nvm --help                                Show this message
  nvm --version                             Print out the installed version of nvm
  nvm install [-s] <version>                Download and install a <version>, [-s] from source. Uses .nvmrc if available
    --reinstall-packages-from=<version>     When installing, reinstall packages installed in <node|iojs|node version number>
    --lts                                   When installing, only select from LTS (long-term support) versions
    --lts=<LTS name>                        When installing, only select from versions for a specific LTS line
    --skip-default-packages                 When installing, skip the default-packages file if it exists
    --latest-npm                            After installing, attempt to upgrade to the latest working npm on the given node version
    --no-progress                           Disable the progress bar on any downloads
  nvm uninstall <version>                   Uninstall a version
  nvm uninstall --lts                       Uninstall using automatic LTS (long-term support) alias `lts/*`, if available.
  nvm uninstall --lts=<LTS name>            Uninstall using automatic alias for provided LTS line, if available.
  nvm use [--silent] <version>              Modify PATH to use <version>. Uses .nvmrc if available
    --lts                                   Uses automatic LTS (long-term support) alias `lts/*`, if available.
    --lts=<LTS name>                        Uses automatic alias for provided LTS line, if available.
  nvm exec [--silent] <version> [<command>] Run <command> on <version>. Uses .nvmrc if available
    --lts                                   Uses automatic LTS (long-term support) alias `lts/*`, if available.
    --lts=<LTS name>                        Uses automatic alias for provided LTS line, if available.
  nvm run [--silent] <version> [<args>]     Run `node` on <version> with <args> as arguments. Uses .nvmrc if available
    --lts                                   Uses automatic LTS (long-term support) alias `lts/*`, if available.
    --lts=<LTS name>                        Uses automatic alias for provided LTS line, if available.
  nvm current                               Display currently activated version of Node
  nvm ls [<version>]                        List installed versions, matching a given <version> if provided
    --no-colors                             Suppress colored output
    --no-alias                              Suppress `nvm alias` output
  nvm ls-remote [<version>]                 List remote versions available for install, matching a given <version> if provided
    --lts                                   When listing, only show LTS (long-term support) versions
    --lts=<LTS name>                        When listing, only show versions for a specific LTS line
    --no-colors                             Suppress colored output
  nvm version <version>                     Resolve the given description to a single local version
  nvm version-remote <version>              Resolve the given description to a single remote version
    --lts                                   When listing, only select from LTS (long-term support) versions
    --lts=<LTS name>                        When listing, only select from versions for a specific LTS line
  nvm deactivate                            Undo effects of `nvm` on current shell
  nvm alias [<pattern>]                     Show all aliases beginning with <pattern>
    --no-colors                             Suppress colored output
  nvm alias <name> <version>                Set an alias named <name> pointing to <version>
  nvm unalias <name>                        Deletes the alias named <name>
  nvm install-latest-npm                    Attempt to upgrade to the latest working `npm` on the current node version
  nvm reinstall-packages <version>          Reinstall global `npm` packages contained in <version> to current version
  nvm unload                                Unload `nvm` from shell
  nvm which [current | <version>]           Display path to installed node version. Uses .nvmrc if available
  nvm cache dir                             Display path to the cache directory for nvm
  nvm cache clear                           Empty cache directory for nvm

Example:
  nvm install 8.0.0                     Install a specific version number
  nvm use 8.0                           Use the latest available 8.0.x release
  nvm run 6.10.3 app.js                 Run app.js using node 6.10.3
  nvm exec 4.8.3 node app.js            Run `node app.js` with the PATH pointing to node 4.8.3
  nvm alias default 8.1.0               Set default node version on a shell
  nvm alias default node                Always default to the latest available node version on a shell

Note:
  to remove, delete, or uninstall nvm - just remove the `$NVM_DIR` folder (usually `~/.nvm`)

root@osboxes:~# which node
root@osboxes:~# nvm install node
Downloading and installing node v14.7.0...
Downloading https://nodejs.org/dist/v14.7.0/node-v14.7.0-linux-x64.tar.xz...
################################################################################################################################################################# 100.0%
Computing checksum with sha256sum
Checksums matched!
/usr/bin/env: ‘node’: No such file or directory
nvm is not compatible with the npm config "prefix" option: currently set to ""
Run `nvm use --delete-prefix v14.7.0` to unset it.
root@osboxes:~# which node
root@osboxes:~# node
-bash: node: command not found
root@osboxes:~# logout
pi@osboxes:~ $ sudo su -
root@osboxes:~# which node
root@osboxes:~# nvm use --delete-prefix v14.7.0
/usr/bin/env: ‘node’: No such file or directory
/usr/bin/env: ‘node’: No such file or directory
root@osboxes:~#

因此,nvm它甚至不会将node可执行文件留在其自身或外壳(即使在重新启动后)可以找到它的任何地方,并建议一个只会产生更多非此类node错误的命令。

任何有关“正确”方法来获得最近node进入这种基于 Debian 的系统的建议表示赞赏。

4

1 回答 1

2

你试过用nvm吗? https://github.com/nvm-sh/nvm

github自述文件还说:

重要笔记

如果您运行的系统没有可用的预打包二进制文件,这意味着您要从其源代码安装 nodejs 或 io.js,您需要确保您的系统具有 C++ 编译器。对于 OS X,Xcode 可以工作,对于基于 Debian/Ubuntu 的 GNU/Linux,build-essential 和 libssl-dev 软件包可以工作。

于 2020-08-09T00:38:54.110 回答