Node.js is a runtime environment that enables the execution of JavaScript outside the browser, making it a critical tool for server-side development. On Ubuntu, you can install Node.js directly from the official package repository, which provides a stable version suitable for most production environments. However, this stable version might not always be the latest, which could be a limitation for projects requiring cutting-edge features.
For users who need the most recent version of Node.js, installing it from NodeSource's PPA is advisable. This approach allows you to access the latest features and updates, ensuring compatibility with the most recent developments in the Node.js ecosystem. Your choice of installation method should be based on whether your project demands the latest version or a stable release.
When setting up Node.js on Ubuntu, it's essential to choose the installation method that best suits your project's requirements. The official repository offers a reliable, stable version, while NodeSource's PPA provides access to the latest version. The stable version is generally recommended for production, while the latest version is better suited for development purposes.
Steps to install Ubuntu's officially supported Node.js:
- Launch terminal.
- Update apt's package list.
$ sudo apt update [sudo] password for user: Hit:1 http://my.archive.ubuntu.com/ubuntu eoan InRelease Hit:2 http://security.ubuntu.com/ubuntu eoan-security InRelease Hit:3 http://my.archive.ubuntu.com/ubuntu eoan-updates InRelease Hit:4 http://my.archive.ubuntu.com/ubuntu eoan-backports InRelease Reading package lists... Done Building dependency tree Reading state information... Done All packages are up to date.
- Install the nodejs package from the official repository.
$ sudo apt install --assume-yes 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 ##### snipped
- Install the npm package if required.
$ sudo apt install --assume-yes npm Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: gyp javascript-common libjs-inherits libjs-is-typedarray libnode-dev libpython-stdlib libpython2-stdlib libpython2.7-minimal libpython2.7-stdlib libssl-dev 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-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-fast-deep-equal 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-gyp 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-schema-traverse 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-uri-js 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 python-minimal python-pkg-resources python2 python2-minimal python2.7 python2.7-minimal Suggested packages: apache2 | lighttpd | httpd libssl-doc python-doc python-tk python-setuptools python2-doc python2.7-doc binfmt-support ##### snipped
- Verify the installed version of nodejs and npm.
$ nodejs -v v10.15.2 $ npm -v 5.8.0
This guide is tested on Ubuntu:
Version | Code Name |
---|---|
22.04 LTS | Jammy Jellyfish |
23.10 | Mantic Minotaur |
24.04 LTS | Noble Numbat |
Mohd Shakir Zakaria is an experienced cloud architect with a strong development and open-source advocacy background. He boasts multiple certifications in AWS, Red Hat, VMware, ITIL, and Linux, underscoring his expertise in cloud architecture and system administration.
Comment anonymously. Login not required.