Debian 11 updates Node.js version

Published on 2023-07-14 at https://chenhaotian.top/debian/d-upd-nodejs/

Steps

Download the required Node.js installation script from the NodeSource service. Pay attention to changing the version number. The current LTS version is 18.x

curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash -

It is now possible to install (update) noedjs directly from apt

sudo apt install -y nodejs

View node version

node -v

Process demonstration

root@VM-PV30VGNA7611:~# curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash -

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


## Populating apt-get cache...

 + apt-get update
Hits: 1 http://deb.debian.org/debian buster InRelease
Hits: 2 http://deb.debian.org/debian buster-updates InRelease
Get: 3 http://deb.debian.org/debian buster-backports InRelease [51.4 kB]
Hits: 4 https://download.docker.com/linux/debian buster InRelease
Hits: 5 http://security.debian.org/debian-security buster/updates InRelease
Downloaded 51.4 kB, took 1 second (62.1 kB/s)
Reading package list... Done

## Confirming "buster" is supported...

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

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

 + curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --dearmor | tee /usr/share/keyrings/nodesource.gpg >/dev/null

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

 + echo 'deb [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_18.x buster main' > /etc/apt/sources.list.d/nodesource. list
 + echo 'deb-src [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_18.x buster main' >> /etc/apt/sources.list.d /nodesource.list

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

 + apt-get update
Hits: 1 http://security.debian.org/debian-security buster/updates InRelease
Hits: 2 http://deb.debian.org/debian buster InRelease
Hits: 3 http://deb.debian.org/debian buster-updates InRelease
Hits: 4 http://deb.debian.org/debian buster-backports InRelease
Hits: 5 https://download.docker.com/linux/debian buster InRelease
Get: 6 https://deb.nodesource.com/node_18.x buster InRelease [4,584 B]
Get: 7 https://deb.nodesource.com/node_18.x buster/main amd64 Packages [776 B]
Downloaded 5,360 B, took 1 second (6,592 B/s)
Reading package list... Done


## Run `sudo apt-get install -y nodejs` to install Node.js 18.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 | gpg --dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null
     echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
     sudo apt-get update & amp; & amp; sudo apt-get install yarn


root@VM-PV30VGNA7611:~# sudo apt install -y nodejs
Reading package list... Done
Analyzing a package's dependency tree
Reading status information... Complete
The following packages were installed automatically and are no longer needed:
  gyp javascript-common libbrotli1 libc-ares2 libjs-inherits libjs-is-typedarray libssl-dev libuv1 libuv1-dev node-abbrev node-ajv node-ansi node-ansi-align
  node-ansi-regex node-ansi-styles node-ansistyles node-aproba node-archy node-are-we-there-yet node-asn1 node-assert-plus node-asynckit node-aws-sign2 node-aws4
  node-balanced-match node-bcrypt-pbkdf node-bluebird node-boxen node-brace-expansion node-builtin-modules node-builtins node-cacache node-call-limit node-camelcase
  node-caseless node-chalk node-chownr node-cli-boxes node-cliui node-clone node-co node-color-convert node-color-name node-combined-stream node-concat-map
  node-concat-stream node-config-chain node-console-control-strings node-copy-concurrently node-core-util-is node-cross-spawn node-cyclist node-dashdash
  node-decamelize node-decompress-response node-deep-extend node-defaults node-delayed-stream node-delegates node-detect-indent node-detect-newline node-duplexer3
  node-duplexify node-ecc-jsbn node-editor node-encoding node-end-of-stream node-errno node-escape-string-regexp node-execa node-extend node-extsprintf node-find-up
  node-flush-write-stream node-forever-agent node-form-data node-from2 node-fs-vacuum node-fs-write-stream-atomic node-fs.realpath node-gauge node-get-caller-file
  node-get-stream node-getpass node-glob node-got node-graceful-fs node-har-schema node-har-validator node-has-flag node-has-symbol-support-x node-has-to-string -tag-x
  node-has-unicode node-hosted-git-info node-http-signature node-iconv-lite node-iferr node-import-lazy node-imurmurhash node-inflight node-inherits node-ini
  node-invert-kv node-is-builtin-module node-is-npm node-is-object node-is-plain-obj node-is-retry-allowed node-is-stream node-is-typedarray node-isarray node -isexe
  node-isstream node-isurl node-jsbn node-json-parse-better-errors node-json-schema node-json-stable-stringify node-json-stringify-safe node-jsonify node-jsonparse
  node-jsonstream node-jsprim node-latest-version node-lazy-property node-lcid node-libnpx node-locate-path node-lockfile node-lowercase-keys node-lru-cache node-mem
  node-mime-types node-mimic-fn node-mimic-response node-minimatch node-minimist node-mississippi node-mkdirp node-move-concurrently node-mute-stream node-node-uuid
  node-nopt node-normalize-package-data node-npm-package-arg node-npm-run-path node-npmlog node-oauth-sign node-object-assign node-once node-opener node-os-locale
  node-osenv node-p-cancelable node-p-finally node-p-limit node-p-locate node-p-timeout node-package-json node-parallel-transform node-path-exists
  node-path-is-absolute node-path-is-inside node-performance-now node-prepend-http node-process-nextick-args node-promise-inflight node-promzard node-proto-list
  node-prr node-pump node-pumpify node-punycode node-qs node-qw node-rc node-read node-read-package-json node-readable-stream node-registry-auth-token
  node-registry-url node-request node-require-directory node-require-main-filename node-resolve-from node-retry node-rimraf node-run-queue node-safe-buffer node-semver
  node-semver-diff node-set-blocking node-sha node-shebang-command node-shebang-regex node-signal-exit node-slash node-slide node-sorted-object node-spdx-correct
  node-spdx-expression-parse node-spdx-license-ids node-sshpk node-ssri node-stream-each node-stream-iterate node-stream-shift node-string-decoder node-string-width
  node-strip-ansi node-strip-eof node-strip-json-comments node-supports-color node-tar node-term-size node-text-table node-through node-through2 node-timed-out
  node-tough-cookie node-tunnel-agent node-tweetnacl node-typedarray node-uid-number node-unique-filename node-unpipe node-url-parse-lax node-url-to-options
  node-util-deprecate node-uuid node-validate-npm-package-license node-validate-npm-package-name node-verror node-wcwidth.js node-which node-which-module
  node-wide-align node-widest-line node-wrap-ansi node-wrappy node-write-file-atomic node-xdg-basedir node-xtend node-y18n node-yallist node-yargs node-yargs-parser
  python-pkg-resources
Use 'sudo apt autoremove' to uninstall it(them).
The following software packages will be [uninstalled]:
  libnode-dev libnode64 node-gyp nodejs-doc npm
The following packages will be upgraded:
  nodejs
1 package upgraded, 0 new packages installed, 5 packages to be uninstalled, and 5 packages not upgraded.
Requires download of 28.7 MB archive.
Decompression consumes 146 MB of additional space.
Get: 1 https://deb.nodesource.com/node_18.x buster/main amd64 nodejs amd64 18.16.1-deb-1nodesource1 [28.7 MB]
Downloaded 28.7 MB, took 1 second (44.7 MB/s)
apt-listchanges: Read change records (changelogs)...
(Reading database... The system currently has a total of 38371 files and directories installed.)
Uninstalling npm (5.8.0 + ds6-4 + deb10u2) ...
Uninstalling node-gyp (3.8.0-6)...
Uninstalling libnode-dev:amd64 (10.24.0~dfsg-1~deb10u3) ...
Uninstalling nodejs-doc (10.24.0~dfsg-1~deb10u3) ...
dpkg: libnode64:amd64: There are dependency issues, but uninstallation will proceed as you expected:
 nodejs depends on libnode64 (= 10.24.0~dfsg-1~deb10u3).

Uninstalling libnode64:amd64 (10.24.0~dfsg-1~deb10u3) ...
(Reading database... The system currently has a total of 35778 files and directories installed.)
Prepare to decompress .../nodejs_18.16.1-deb-1nodesource1_amd64.deb ...
Unpacking nodejs (18.16.1-deb-1nodesource1) and overwriting (10.24.0~dfsg-1~deb10u3)...
Setting up nodejs (18.16.1-deb-1nodesource1) ...
Processing triggers for libc-bin (2.28-10 + deb10u2) ...
Processing triggers for man-db (2.8.5-2) ...
root@VM-PV30VGNA7611:~# node -v
v18.16.1