Ubuntu22.04系统下升级nodejs到v18版本
作者:iHero
ubuntu默认安装的nodejs版本比较老,要安装到最新的,下面这篇文章主要给大家介绍了关于Ubuntu22.04系统下升级nodejs到v18版本的相关资料,文中通过代码介绍的非常详细,需要的朋友可以参考下
前言
Ubuntu 22.04 已经安装的nodejs 版本 nodejs is already the newest version (12.22.9~dfsg-1ubuntu3.3).
删除以前的 nodejs 版本:
1. sudo apt remove nodejs
root@erp:~# sudo apt remove nodejs Reading package lists... Done Building dependency tree... Done Reading state information... Done The following packages were automatically installed and are no longer required: gyp libintl-perl libintl-xs-perl libjs-events libjs-highlight.js libjs-inherits libjs-is-typedarray libjs-psl libjs-source-map libjs-sprintf-js libjs-typedarray-to-buffer libmodule-find-perl libmodule-scandeps-perl libnode-dev libnode72 libnotify-bin libproc-processtable-perl libsort-naturally-perl libuv1-dev node-abbrev node-ansi-regex node-ansi-styles node-ansistyles node-are-we-there-yet node-arrify node-asap node-asynckit node-balanced-match node-brace-expansion node-chownr node-clean-yaml-object node-color-convert node-color-name node-commander node-core-util-is node-decompress-response node-delayed-stream node-delegates node-depd node-diff node-encoding node-end-of-stream node-err-code node-escape-string-regexp node-fancy-log node-foreground-child node-fs.realpath node-function-bind node-get-stream node-glob node-growl node-has-flag node-has-unicode node-hosted-git-info node-iconv-lite node-iferr node-imurmurhash node-indent-string node-inflight node-inherits node-ini node-ip node-ip-regex node-is-buffer node-is-plain-obj node-is-typedarray node-isarray node-isexe node-json-parse-better-errors node-jsonparse node-kind-of node-lodash-packages node-lowercase-keys node-lru-cache node-mimic-response node-minimatch node-minimist node-minipass node-mute-stream node-negotiator node-npm-bundled node-once node-osenv node-p-cancelable node-p-map node-path-is-absolute node-process-nextick-args node-promise-inflight node-promise-retry node-promzard node-pump node-quick-lru node-read node-readable-stream node-resolve node-retry node-safe-buffer node-set-blocking node-signal-exit node-slash node-slice-ansi node-source-map node-spdx-correct node-spdx-exceptions node-spdx-expression-parse node-spdx-license-ids node-sprintf-js node-stealthy-require node-string-decoder node-supports-color node-text-table node-time-stamp node-tmatch node-typedarray-to-buffer node-universalify node-util-deprecate node-validate-npm-package-license node-webidl-conversions node-whatwg-fetch node-wrappy node-yallist nodejs-doc Use 'sudo apt autoremove' to remove them. The following packages will be REMOVED: node-abab node-agent-base node-aproba node-archy node-argparse node-builtins node-cacache node-chalk node-cli-table node-clone node-colors node-columnify node-combined-stream node-console-control-strings node-copy-concurrently node-coveralls node-cssom node-cssstyle node-debug node-defaults node-esprima node-events node-fetch node-form-data node-fs-write-stream-atomic node-gauge node-got node-graceful-fs node-gyp node-https-proxy-agent node-js-yaml node-jsdom node-json-buffer node-lcov-parse node-log-driver node-mime node-mime-types node-mkdirp node-move-concurrently node-ms node-nopt node-normalize-package-data node-npm-package-arg node-npmlog node-object-assign node-opener node-psl node-punycode node-read-package-json node-rimraf node-run-queue node-semver node-source-map-support node-ssri node-stack-utils node-string-width node-strip-ansi node-tap node-tap-mocha-reporter node-tap-parser node-tar node-tough-cookie node-unique-filename node-validate-npm-package-name node-wcwidth.js node-which node-wide-align node-write-file-atomic node-ws nodejs npm 0 upgraded, 0 newly installed, 71 to remove and 65 not upgraded. After this operation, 14.0 MB disk space will be freed. Do you want to continue? [Y/n] y (Reading database ... 175903 files and directories currently installed.) Removing node-coveralls (3.1.1-1) ... Removing node-fetch (2.6.7+~2.5.12-1) ... Removing node-jsdom (19.0.0+~cs90.11.27-1) ... Removing node-abab (2.0.5-2) ... Removing npm (8.5.1~ds-1) ... Removing node-ws (8.5.0+~cs13.3.3-2) ... Removing node-https-proxy-agent (5.0.0+~cs8.0.0-3) ... Removing node-agent-base (6.0.2+~cs5.4.2-1) ... Removing node-cacache (15.0.5+~cs13.9.21-3) ... Removing node-move-concurrently (1.0.1-4) ... Removing node-copy-concurrently (1.0.5-8) ... Removing node-run-queue (2.0.0-2) ... Removing node-archy (1.0.0-4) ... Removing node-tap (12.0.1+ds-4) ... Removing node-tap-mocha-reporter (3.0.7+ds-2) ... Removing node-tap-parser (7.0.0+ds1-6) ... Removing node-js-yaml (4.1.0+dfsg+~4.0.5-6) ... Removing node-argparse (2.0.1-2) ... Removing node-npm-package-arg (8.1.5-1) ... Removing node-validate-npm-package-name (3.0.0-4) ... Removing node-builtins (4.0.0-1) ... Removing node-chalk (4.1.2-1) ... Removing node-cli-table (0.3.11+~cs0.13.3-1) ... Removing node-columnify (1.5.4+~1.5.1-1) ... Removing node-gyp (8.4.1-1) ... Removing node-npmlog (6.0.1+~4.1.4-1) ... Removing node-gauge (4.0.2-1) ... Removing node-wide-align (1.1.3-4) ... Removing node-string-width (4.2.3+~cs13.2.3-1) ... Removing node-wcwidth.js (1.0.2-1) ... Removing node-defaults (1.0.3+~1.0.3-1) ... Removing node-clone (2.1.2-3) ... Removing node-colors (1.4.0-3) ... Removing node-form-data (3.0.1-1) ... Removing node-combined-stream (1.0.8+~1.0.3-1) ... Removing node-console-control-strings (1.1.0-2) ... Removing node-cssstyle (2.3.0-2) ... Removing node-cssom (0.4.4-3) ... Removing node-debug (4.3.2+~cs4.1.7-1) ... Removing node-esprima (4.0.1+ds+~4.0.3-2) ... Removing node-events (3.3.0+~3.0.0-2) ... Removing node-fs-write-stream-atomic (1.0.10-5) ... Removing node-got (11.8.3+~cs58.7.37-1) ... Removing node-graceful-fs (4.2.4+repack-1) ... Removing node-json-buffer (3.0.1-1) ... Removing node-lcov-parse (1.0.0+20170612git80d039574ed9-5) ... Removing node-log-driver (1.2.7+git+20180219+bba1761737-7) ... Removing node-mime-types (2.1.33-1) ... Removing node-mime (3.0.0+dfsg+~cs3.96.1-1) ... Removing node-tar (6.1.11+ds1+~cs6.0.6-1) ... Removing node-mkdirp (1.0.4+~1.0.2-1) ... Removing node-ms (2.1.3+~cs0.7.31-2) ... Removing node-nopt (5.0.0-2) ... Removing node-read-package-json (4.1.1-1) ... Removing node-normalize-package-data (3.0.3+~2.4.1-1) ... Removing node-object-assign (4.1.1-6) ... Removing node-opener (1.5.2+~1.4.0-1) ... Removing node-tough-cookie (4.0.0-2) ... Removing node-psl (1.8.0+ds-6) ... Removing node-punycode (2.1.1-5) ... Removing node-rimraf (3.0.2-1) ... Removing node-semver (7.3.5+~7.3.8-1) ... Removing node-source-map-support (0.5.21+ds+~0.5.4-1) ... Removing node-ssri (8.0.1-2) ... Removing node-stack-utils (2.0.5+~2.0.1-1) ... Removing node-strip-ansi (6.0.1-1) ... Removing node-unique-filename (1.1.1+ds-1) ... Removing node-which (2.0.2+~cs1.3.2-2) ... Removing node-write-file-atomic (3.0.3+~3.0.2-1) ... Removing node-aproba (2.0.0-2) ... Removing nodejs (12.22.9~dfsg-1ubuntu3.3) ... Processing triggers for man-db (2.10.2-1) ...
2. sudo apt autoremove
root@erp:~# sudo apt autoremove Reading package lists... Done Building dependency tree... Done Reading state information... Done The following packages will be REMOVED: gyp libintl-perl libintl-xs-perl libjs-events libjs-highlight.js libjs-inherits libjs-is-typedarray libjs-psl libjs-source-map libjs-sprintf-js libjs-typedarray-to-buffer libmodule-find-perl libmodule-scandeps-perl libnode-dev libnode72 libnotify-bin libproc-processtable-perl libsort-naturally-perl libuv1-dev node-abbrev node-ansi-regex node-ansi-styles node-ansistyles node-are-we-there-yet node-arrify node-asap node-asynckit node-balanced-match node-brace-expansion node-chownr node-clean-yaml-object node-color-convert node-color-name node-commander node-core-util-is node-decompress-response node-delayed-stream node-delegates node-depd node-diff node-encoding node-end-of-stream node-err-code node-escape-string-regexp node-fancy-log node-foreground-child node-fs.realpath node-function-bind node-get-stream node-glob node-growl node-has-flag node-has-unicode node-hosted-git-info node-iconv-lite node-iferr node-imurmurhash node-indent-string node-inflight node-inherits node-ini node-ip node-ip-regex node-is-buffer node-is-plain-obj node-is-typedarray node-isarray node-isexe node-json-parse-better-errors node-jsonparse node-kind-of node-lodash-packages node-lowercase-keys node-lru-cache node-mimic-response node-minimatch node-minimist node-minipass node-mute-stream node-negotiator node-npm-bundled node-once node-osenv node-p-cancelable node-p-map node-path-is-absolute node-process-nextick-args node-promise-inflight node-promise-retry node-promzard node-pump node-quick-lru node-read node-readable-stream node-resolve node-retry node-safe-buffer node-set-blocking node-signal-exit node-slash node-slice-ansi node-source-map node-spdx-correct node-spdx-exceptions node-spdx-expression-parse node-spdx-license-ids node-sprintf-js node-stealthy-require node-string-decoder node-supports-color node-text-table node-time-stamp node-tmatch node-typedarray-to-buffer node-universalify node-util-deprecate node-validate-npm-package-license node-webidl-conversions node-whatwg-fetch node-wrappy node-yallist nodejs-doc 0 upgraded, 0 newly installed, 122 to remove and 65 not upgraded. After this operation, 81.0 MB disk space will be freed. Do you want to continue? [Y/n] y (Reading database ... 172820 files and directories currently installed.) Removing gyp (0.1+20210831gitd6c5dd5-5) ... Removing libintl-xs-perl (1.26-3build2) ... Removing libintl-perl (1.26-3build2) ... Removing libjs-events (3.3.0+~3.0.0-2) ... Removing nodejs-doc (12.22.9~dfsg-1ubuntu3.3) ... Removing libjs-highlight.js (9.18.5+dfsg1-1) ... Removing node-are-we-there-yet (3.0.0+~1.1.0-1) ... Removing node-readable-stream (3.6.0+~cs3.0.0-1) ... Removing node-glob (7.2.1+~cs7.6.15-1) ... Removing node-inherits (2.0.4-4) ... Removing libjs-inherits (2.0.4-4) ... Removing node-typedarray-to-buffer (4.0.0-2) ... Removing node-is-typedarray (1.0.0-4) ... Removing libjs-is-typedarray (1.0.0-4) ... Removing libjs-psl (1.8.0+ds-6) ... Removing node-source-map (0.7.0++dfsg2+really.0.6.1-9) ... Removing libjs-source-map (0.7.0++dfsg2+really.0.6.1-9) ... Removing node-sprintf-js (1.1.2+ds1+~1.1.2-1) ... Removing libjs-sprintf-js (1.1.2+ds1+~1.1.2-1) ... Removing libjs-typedarray-to-buffer (4.0.0-2) ... Removing libmodule-find-perl (0.15-1) ... Removing libmodule-scandeps-perl (1.31-1) ... Removing libnode-dev (12.22.9~dfsg-1ubuntu3.3) ... Removing libnode72:amd64 (12.22.9~dfsg-1ubuntu3.3) ... Removing node-growl (1.10.5-4) ... Removing libnotify-bin (0.7.9-3ubuntu5.22.04.1) ... Removing libproc-processtable-perl:amd64 (0.634-1build1) ... Removing libsort-naturally-perl (1.03-2) ... Removing libuv1-dev:amd64 (1.43.0-1) ... Removing node-abbrev (1.1.1+~1.1.2-1) ... Removing node-ansi-regex (5.0.1-1) ... Removing node-slice-ansi (5.0.0+~cs9.0.0-4) ... Removing node-ansi-styles (4.3.0+~4.2.0-1) ... Removing node-ansistyles (0.1.3-5) ... Removing node-minimist (1.2.5+~cs5.3.2-1) ... Removing node-arrify (2.0.1-2) ... Removing node-asap (2.0.6+~2.0.0-1) ... Removing node-asynckit (0.4.0-4) ... Removing node-minimatch (3.1.1+~3.0.5-1) ... Removing node-brace-expansion (2.0.1-1) ... Removing node-balanced-match (2.0.0-1) ... Removing node-chownr (2.0.0-1) ... Removing node-clean-yaml-object (0.1.0-5) ... Removing node-color-convert (2.0.1-1) ... Removing node-color-name (1.1.4+~1.1.1-2) ... Removing node-commander (9.0.0-2) ... Removing node-core-util-is (1.0.3-1) ... Removing node-decompress-response (6.0.0-2) ... Removing node-delayed-stream (1.0.0-5) ... Removing node-delegates (1.0.0-3) ... Removing node-depd (2.0.0-2) ... Removing node-diff (5.0.0~dfsg+~5.0.1-3) ... Removing node-minipass (3.1.6+~cs8.7.18-1) ... Removing node-encoding (0.1.13-2) ... Removing node-get-stream (6.0.1-1) ... Removing node-pump (3.0.0-5) ... Removing node-end-of-stream (1.4.4+~1.4.1-1) ... Removing node-promise-retry (2.0.1-2) ... Removing node-err-code (2.0.3+dfsg-3) ... Removing node-p-map (4.0.0+~3.1.0+~3.0.1-1) ... Removing node-escape-string-regexp (4.0.0-2) ... Removing node-fancy-log (1.3.3+~cs1.3.1-2) ... Removing node-foreground-child (2.0.0-3) ... Removing node-fs.realpath (1.0.0-2) ... Removing node-resolve (1.20.0+~cs5.27.9-1) ... Removing node-function-bind (1.1.1+repacked+~1.0.3-1) ... Removing node-supports-color (8.1.1+~8.1.1-1) ... Removing node-has-flag (4.0.0-2) ... Removing node-has-unicode (2.0.1-4) ... Removing node-hosted-git-info (4.0.2-1) ... Removing node-iconv-lite (0.6.3-2) ... Removing node-iferr (1.0.2+~1.0.2-1) ... Removing node-imurmurhash (0.1.4+dfsg+~0.1.1-1) ... Removing node-indent-string (4.0.0-2) ... Removing node-inflight (1.0.6-2) ... Removing node-ini (2.0.1-1) ... Removing node-ip (1.1.5+~1.1.0-1) ... Removing node-ip-regex (4.3.0+~4.1.1-1) ... Removing node-kind-of (6.0.3+dfsg-2) ... Removing node-is-buffer (2.0.5-2) ... Removing node-is-plain-obj (3.0.0-2) ... Removing node-isarray (2.0.5-3) ... Removing node-isexe (2.0.0+~2.0.1-4) ... Removing node-json-parse-better-errors (1.0.2+~cs3.3.1-1) ... Removing node-jsonparse (1.3.1-10) ... Removing node-lodash-packages (4.17.21+dfsg+~cs8.31.198.20210220-5) ... Removing node-lowercase-keys (2.0.0-2) ... Removing node-lru-cache (6.0.0+~5.1.1-1) ... Removing node-mimic-response (3.1.0-7) ... Removing node-promzard (0.3.0-2) ... Removing node-read (1.0.7-3) ... Removing node-mute-stream (0.0.8+~0.0.1-1) ... Removing node-negotiator (0.6.2+~0.6.1-1) ... Removing node-npm-bundled (1.1.2-1) ... Removing node-once (1.4.0-4) ... Removing node-osenv (0.1.5+~0.1.0-1) ... Removing node-p-cancelable (2.1.1-1) ... Removing node-path-is-absolute (2.0.0-2) ... Removing node-process-nextick-args (2.0.1-2) ... Removing node-promise-inflight (1.0.1+~1.0.0-1) ... Removing node-quick-lru (5.1.1-1) ... Removing node-retry (0.13.1+~0.12.1-1) ... Removing node-string-decoder (1.3.0-5) ... Removing node-safe-buffer (5.2.1+~cs2.1.2-2) ... Removing node-set-blocking (2.0.0-2) ... Removing node-signal-exit (3.0.6+~3.0.1-1) ... Removing node-slash (3.0.0-2) ... Removing node-validate-npm-package-license (3.0.4-2) ... Removing node-spdx-correct (3.1.1-2) ... Removing node-spdx-expression-parse (3.0.1+~3.0.1-1) ... Removing node-spdx-exceptions (2.3.0-2) ... Removing node-spdx-license-ids (3.0.11-1) ... Removing node-stealthy-require (1.1.1-5) ... Removing node-text-table (0.2.0-4) ... Removing node-time-stamp (2.2.0-1) ... Removing node-tmatch (5.0.0-4) ... Removing node-universalify (2.0.0-3) ... Removing node-util-deprecate (1.0.2-3) ... Removing node-webidl-conversions (7.0.0~1.1.0+~cs15.1.20180823-2) ... Removing node-whatwg-fetch (3.6.2-5) ... Removing node-wrappy (1.0.2-2) ... Removing node-yallist (4.0.0+~4.0.1-1) ... Processing triggers for man-db (2.10.2-1) ...
安装 nodejs v18
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - &&\ sudo apt-get install -y nodejs
查看 nodejs 版本
nodejs -v v18.19.0
遇到的问题
2024-02-07 16:59:23 - Error: Failed to run ‘apt-get update’ (Exit Code: 0)
root@erp:~# curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - &&\ sudo apt-get install -y nodejs 2024-02-07 16:59:10 - Installing pre-requisites Hit:1 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy InRelease Hit:2 https://download.docker.com/linux/ubuntu jammy InRelease Hit:4 http://apt.postgresql.org/pub/repos/apt jammy-pgdg InRelease Hit:3 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates InRelease Hit:5 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-backports InRelease Hit:6 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-security InRelease Hit:7 https://ppa.launchpadcontent.net/ondrej/php/ubuntu jammy InRelease Ign:8 https://www.collaboraoffice.com/repos/CollaboraOnline/23.05/customer-deb- ./ InRelease Get:9 https://www.collaboraoffice.com/repos/CollaboraOnline/CODE-ubuntu2204 ./ InRelease [1,728 B] Err:9 https://www.collaboraoffice.com/repos/CollaboraOnline/CODE-ubuntu2204 ./ InRelease The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 0C54D189F4BA284D Get:10 https://www.collaboraoffice.com/repos/CollaboraOnline/23.05/customer-deb- ./ Release Ign:11 https://www.collaboraoffice.com/repos/CollaboraOnline/23.05/customer-deb- ./ Release.gpg Reading package lists... Done W: https://download.docker.com/linux/ubuntu/dists/jammy/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details. W: GPG error: https://www.collaboraoffice.com/repos/CollaboraOnline/CODE-ubuntu2204 ./ InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 0C54D189F4BA284D E: The repository 'https://www.collaboraoffice.com/repos/CollaboraOnline/CODE-ubuntu2204 ./ InRelease' is not signed. N: Updating from such a repository can't be done securely, and is therefore disabled by default. N: See apt-secure(8) manpage for repository creation and user configuration details. E: The repository 'https://www.collaboraoffice.com/repos/CollaboraOnline/23.05/customer-deb- ./ Release' is not signed. N: Updating from such a repository can't be done securely, and is therefore disabled by default. N: See apt-secure(8) manpage for repository creation and user configuration details. 2024-02-07 16:59:23 - Error: Failed to run 'apt-get update' (Exit Code: 0)
查看是 CollaboraOnline 造成的
cd /etc/apt/sources.list.d/ # 修改或者删除CollaboraOnline list sudo apt-get update # 问题解决
总结
到此这篇关于Ubuntu22.04系统下升级nodejs到v18版本的文章就介绍到这了,更多相关Ubuntu升级nodejs v18内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!