title: How to install working recent node (stable/12.x) on Raspbian/Debian?
body: <p>Trying to install stable nodejs (12.x) on a Debian-Buster based machine – specifically this <a href="https://www.osboxes.org/raspbian/#raspbian-2019-09-30-info" rel="nofollow noreferrer">Raspbian VM image</a>. But everything fails in new, weird ways - like leaving <code>node</code> at 10.21.0, or installing a <code>node</code> executable that's obviously there but gives a <code>no such file or directory</code> error when executed.</p>
  <p>Let's try the <a href="https://github.com/nodesource/distributions#debinstall" rel="nofollow noreferrer">instructions from NodeSource</a> for getting 12.x at a fresh terminal:</p>
  <pre><code>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 &quot;buster&quot; 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' &gt; /etc/apt/sources.list.d/nodesource.list
  + echo 'deb-src https://deb.nodesource.com/node_12.x buster main' &gt;&gt; /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 &quot;deb https://dl.yarnpkg.com/debian/ stable main&quot; | sudo tee /etc/apt/sources.list.d/yarn.list
       sudo apt-get update &amp;&amp; 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:~#
  </code></pre>
  <p>OK, no luck there. <a href="https://stackoverflow.com/a/53592807/130288">Some people seem to like <code>n</code> for node-install/versioning</a>. Starting over from fresh image (without effects of above attempt, except for the <code>apt-get-update</code>):</p>
  <pre><code>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:~# 
  </code></pre>
  <p>OK, there's definitely an executable there, but it gives a mysterious <code>-bash: /root/n/bin/node: No such file or directory</code> error on execution. (Did <code>n</code> install the wrong architecture/binary?)</p>
  <p>Below, ~Temonocher suggests trying <code>nvm</code>. OK, again starting fresh with non of the detritus from those earlier attempts:</p>
  <pre><code>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
  =&gt; Downloading nvm from git to '/root/.nvm'
  =&gt; 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.
  =&gt; Compressing and cleaning up git repository
  
  =&gt; Appending nvm source string to /root/.bashrc
  =&gt; Appending bash_completion source string to /root/.bashrc
  =&gt; Close and reopen your terminal to start using nvm or run the following to use it now:
  
  export NVM_DIR=&quot;$HOME/.nvm&quot;
  [ -s &quot;$NVM_DIR/nvm.sh&quot; ] &amp;&amp; \. &quot;$NVM_DIR/nvm.sh&quot;  # This loads nvm
  [ -s &quot;$NVM_DIR/bash_completion&quot; ] &amp;&amp; \. &quot;$NVM_DIR/bash_completion&quot;  # This loads nvm bash_completion
  root@osboxes:~# export NVM_DIR=&quot;$HOME/.nvm&quot;
  root@osboxes:~# [ -s &quot;$NVM_DIR/nvm.sh&quot; ] &amp;&amp; \. &quot;$NVM_DIR/nvm.sh&quot;  # This loads nvm
  root@osboxes:~# [ -s &quot;$NVM_DIR/bash_completion&quot; ] &amp;&amp; \. &quot;$NVM_DIR/bash_completion&quot;  # This loads nvm bash_completion
  root@osboxes:~# nvm -v
  
  Node Version Manager (v0.35.3)
  
  Note: &lt;version&gt; refers to any version-like string nvm understands. This includes:
    - full or partial version numbers, starting with an optional &quot;v&quot; (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] &lt;version&gt;                Download and install a &lt;version&gt;, [-s] from source. Uses .nvmrc if available
      --reinstall-packages-from=&lt;version&gt;     When installing, reinstall packages installed in &lt;node|iojs|node version number&gt;
      --lts                                   When installing, only select from LTS (long-term support) versions
      --lts=&lt;LTS name&gt;                        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 &lt;version&gt;                   Uninstall a version
    nvm uninstall --lts                       Uninstall using automatic LTS (long-term support) alias `lts/*`, if available.
    nvm uninstall --lts=&lt;LTS name&gt;            Uninstall using automatic alias for provided LTS line, if available.
    nvm use [--silent] &lt;version&gt;              Modify PATH to use &lt;version&gt;. Uses .nvmrc if available
      --lts                                   Uses automatic LTS (long-term support) alias `lts/*`, if available.
      --lts=&lt;LTS name&gt;                        Uses automatic alias for provided LTS line, if available.
    nvm exec [--silent] &lt;version&gt; [&lt;command&gt;] Run &lt;command&gt; on &lt;version&gt;. Uses .nvmrc if available
      --lts                                   Uses automatic LTS (long-term support) alias `lts/*`, if available.
      --lts=&lt;LTS name&gt;                        Uses automatic alias for provided LTS line, if available.
    nvm run [--silent] &lt;version&gt; [&lt;args&gt;]     Run `node` on &lt;version&gt; with &lt;args&gt; as arguments. Uses .nvmrc if available
      --lts                                   Uses automatic LTS (long-term support) alias `lts/*`, if available.
      --lts=&lt;LTS name&gt;                        Uses automatic alias for provided LTS line, if available.
    nvm current                               Display currently activated version of Node
    nvm ls [&lt;version&gt;]                        List installed versions, matching a given &lt;version&gt; if provided
      --no-colors                             Suppress colored output
      --no-alias                              Suppress `nvm alias` output
    nvm ls-remote [&lt;version&gt;]                 List remote versions available for install, matching a given &lt;version&gt; if provided
      --lts                                   When listing, only show LTS (long-term support) versions
      --lts=&lt;LTS name&gt;                        When listing, only show versions for a specific LTS line
      --no-colors                             Suppress colored output
    nvm version &lt;version&gt;                     Resolve the given description to a single local version
    nvm version-remote &lt;version&gt;              Resolve the given description to a single remote version
      --lts                                   When listing, only select from LTS (long-term support) versions
      --lts=&lt;LTS name&gt;                        When listing, only select from versions for a specific LTS line
    nvm deactivate                            Undo effects of `nvm` on current shell
    nvm alias [&lt;pattern&gt;]                     Show all aliases beginning with &lt;pattern&gt;
      --no-colors                             Suppress colored output
    nvm alias &lt;name&gt; &lt;version&gt;                Set an alias named &lt;name&gt; pointing to &lt;version&gt;
    nvm unalias &lt;name&gt;                        Deletes the alias named &lt;name&gt;
    nvm install-latest-npm                    Attempt to upgrade to the latest working `npm` on the current node version
    nvm reinstall-packages &lt;version&gt;          Reinstall global `npm` packages contained in &lt;version&gt; to current version
    nvm unload                                Unload `nvm` from shell
    nvm which [current | &lt;version&gt;]           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 &quot;prefix&quot; option: currently set to &quot;&quot;
  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:~#
  </code></pre>
  <p>So, <code>nvm</code> doesn't even leave a <code>node</code> executable anywhere where either itself or the shell (even after relaunch) can find it, and suggests a command that just generates more no-such-<code>node</code> errors.</p>
  <p>Any suggestions for the 'right' way to get a recent <code>node</code> onto such a Debian-based system appreciated.</p>