Install node and npm in ubuntu 22.04 minimal install
Installing nodejs
sudo apt-get install -y ca-certificates curl gnupg
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
then execute this
NODE_MAJOR=18
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
sudo apt-get update
sudo apt-get install nodejs -y
node -v
#v18.18.1
then to install npm
if you attempt to install with apt you are getting this error
ubuntu@scratchbox:~$ sudo apt install npm
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
npm : Depends: node-agent-base but it is not going to be installed
Depends: node-aproba but it is not going to be installed
Depends: node-archy but it is not going to be installed
Depends: node-cacache but it is not going to be installed
Depends: node-chalk but it is not going to be installed
Depends: node-cli-table3
Depends: node-colors but it is not going to be installed
Depends: node-columnify but it is not going to be installed
Depends: node-debug but it is not going to be installed
Depends: node-emoji-regex
Depends: node-got but it is not going to be installed
Depends: node-graceful-fs but it is not going to be installed
Depends: node-gyp but it is not going to be installed
Depends: node-https-proxy-agent but it is not going to be installed
Depends: node-mkdirp but it is not going to be installed
Depends: node-ms but it is not going to be installed
Depends: node-nopt but it is not going to be installed
Depends: node-normalize-package-data but it is not going to be installed
Depends: node-npm-package-arg but it is not going to be installed
Depends: node-npmlog but it is not going to be installed
Depends: node-read-package-json but it is not going to be installed
Depends: node-rimraf but it is not going to be installed
Depends: node-semver but it is not going to be installed
Depends: node-ssri but it is not going to be installed
Depends: node-string-width but it is not going to be installed
Depends: node-strip-ansi but it is not going to be installed
Depends: node-tar but it is not going to be installed
Depends: node-validate-npm-package-name but it is not going to be installed
Depends: node-which but it is not going to be installed
Depends: node-write-file-atomic but it is not going to be installed
Depends: nodejs:any (>= 10)
Recommends: git but it is not going to be installed
Recommends: node-tap but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
execute the following commands
sudo apt-get install aptitude
sudo aptitude install npm
this the output
ubuntu@scratchbox:~$ sudo aptitude install npm
The following NEW packages will be installed:
git{a} git-man{a} javascript-common{a} less{a} liberror-perl{a} libjs-events{a} libjs-inherits{a} libjs-is-typedarray{a}
libjs-typedarray-to-buffer{a} node-abbrev{a} node-agent-base{a} node-ansi-regex{a} node-ansi-styles{a} node-ansistyles{a}
node-aproba{a} node-archy{a} node-are-we-there-yet{a} node-asap{a} node-balanced-match{a} node-brace-expansion{a} node-builtins{a}
node-chalk{a} node-chownr{a} node-cli-table{a} node-clone{a} node-color-convert{a} node-color-name{a} node-colors{a} node-columnify{a}
node-console-control-strings{a} node-core-util-is{a} node-debug{a} node-decompress-response{a} node-defaults{a} node-delegates{a}
node-depd{a} node-encoding{a} node-end-of-stream{a} node-err-code{a} node-escape-string-regexp{a} node-events{a} node-fancy-log{a}
node-fs.realpath{a} node-function-bind{a} node-gauge{a} node-get-stream{a} node-glob{a} node-got{a} node-graceful-fs{a}
node-has-flag{a} node-has-unicode{a} node-hosted-git-info{a} node-https-proxy-agent{a} node-iconv-lite{a} node-imurmurhash{a}
node-inflight{a} node-inherits{a} node-ini{a} node-ip{a} node-ip-regex{a} node-is-typedarray{a} node-isarray{a} node-json-buffer{a}
node-json-parse-better-errors{a} node-jsonparse{a} node-lowercase-keys{a} node-lru-cache{a} node-mimic-response{a} node-minimatch{a}
node-minipass{a} node-ms{a} node-mute-stream{a} node-negotiator{a} node-normalize-package-data{a} node-npm-bundled{a}
node-npm-package-arg{a} node-npmlog{a} node-object-assign{a} node-once{a} node-osenv{a} node-p-cancelable{a} node-path-is-absolute{a}
node-process-nextick-args{a} node-promise-retry{a} node-promzard{a} node-pump{a} node-quick-lru{a} node-read{a}
node-read-package-json{a} node-readable-stream{a} node-resolve{a} node-retry{a} node-rimraf{a} node-safe-buffer{a} node-semver{a}
node-set-blocking{a} node-signal-exit{a} node-slash{a} node-slice-ansi{a} node-spdx-correct{a} node-spdx-exceptions{a}
node-spdx-expression-parse{a} node-spdx-license-ids{a} node-ssri{a} node-string-decoder{a} node-string-width{a} node-strip-ansi{a}
node-supports-color{a} node-text-table{a} node-time-stamp{a} node-typedarray-to-buffer{a} node-util-deprecate{a}
node-validate-npm-package-license{a} node-validate-npm-package-name{a} node-wcwidth.js{a} node-wide-align{a} node-wrappy{a}
node-write-file-atomic{a} node-yallist{a} npm{b}
0 packages upgraded, 120 newly installed, 0 to remove and 7 not upgraded.
Need to get 6524 kB of archives. After unpacking 29.0 MB will be used.
The following packages have unmet dependencies:
npm : Depends: node-cacache but it is not installable
Depends: node-gyp but it is not installable
Depends: node-mkdirp but it is not installable
Depends: node-nopt but it is not installable
Depends: node-tar but it is not installable
Depends: node-which but it is not installable
Depends: nodejs:any (>= 10) which is a virtual package, provided by:
- nodejs (12.22.9~dfsg-1ubuntu3), but 18.18.1-1nodesource1 is installed
nodejs : Conflicts: npm but 8.5.1~ds-1 is to be installed
The following actions will resolve these dependencies:
Keep the following packages at their current version:
1) npm [Not Installed]
Accept this solution? [Y/n/q/?]
The following NEW packages will be installed:
git{a} git-man{a} less{a} liberror-perl{a}
0 packages upgraded, 4 newly installed, 0 to remove and 7 not upgraded.
Need to get 4289 kB of archives. After unpacking 21.3 MB will be used.
Do you want to continue? [Y/n/?]
Get: 1 http://phx-ad-3.clouds.archive.ubuntu.com/ubuntu jammy-updates/main amd64 less amd64 590-1ubuntu0.22.04.1 [143 kB]
Get: 2 http://phx-ad-3.clouds.archive.ubuntu.com/ubuntu jammy/main amd64 liberror-perl all 0.17029-1 [26.5 kB]
Get: 3 http://phx-ad-3.clouds.archive.ubuntu.com/ubuntu jammy-updates/main amd64 git-man all 1:2.34.1-1ubuntu1.10 [954 kB]
Get: 4 http://phx-ad-3.clouds.archive.ubuntu.com/ubuntu jammy-updates/main amd64 git amd64 1:2.34.1-1ubuntu1.10 [3166 kB]
Fetched 4289 kB in 1s (4059 kB/s)
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package less.
(Reading database ... 100409 files and directories currently installed.)
Preparing to unpack .../less_590-1ubuntu0.22.04.1_amd64.deb ...
Unpacking less (590-1ubuntu0.22.04.1) ...
Selecting previously unselected package liberror-perl.
Preparing to unpack .../liberror-perl_0.17029-1_all.deb ...
Unpacking liberror-perl (0.17029-1) ...
Selecting previously unselected package git-man.
Preparing to unpack .../git-man_1%3a2.34.1-1ubuntu1.10_all.deb ...
Unpacking git-man (1:2.34.1-1ubuntu1.10) ...
Selecting previously unselected package git.
Preparing to unpack .../git_1%3a2.34.1-1ubuntu1.10_amd64.deb ...
Unpacking git (1:2.34.1-1ubuntu1.10) ...
Setting up less (590-1ubuntu0.22.04.1) ...
Setting up liberror-perl (0.17029-1) ...
Setting up git-man (1:2.34.1-1ubuntu1.10) ...
Setting up git (1:2.34.1-1ubuntu1.10) ...
debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 78.)
debconf: falling back to frontend: Readline
Scanning processes...
Scanning linux images...
Running kernel seems to be up-to-date.
No services need to be restarted.
No containers need to be restarted.
No user sessions are running outdated binaries.
No VM guests are running outdated hypervisor (qemu) binaries on this host.
ubuntu@scratchbox:~$ npm -v
9.8.1
then upgrade
sudo npm install -g npm@latest
#npm -v
#10.2.0
sudo npm install --global yarn