Home > Web Front-end > JS Tutorial > Quick Tip: Install Node.js on Ubuntu

Quick Tip: Install Node.js on Ubuntu

William Shakespeare
Release: 2025-02-08 09:27:09
Original
927 people have browsed it

Quick Tip: Install Node.js on Ubuntu

This guide details three methods for installing Node.js on Ubuntu, a popular Linux distribution. We'll cover prerequisites, environment setup, and uninstallation.

Key Benefits:

  • Master Node.js and npm installation via the default repository, NodeSource, or NVM (Node Version Manager).
  • Configure your development environment, including project creation and basic program execution.
  • Learn how to remove Node.js using either apt or NVM, depending on your chosen installation method.

Understanding Node.js:

Node.js is a JavaScript runtime environment for building scalable server-side applications and APIs. Its event-driven architecture and non-blocking I/O model make it ideal for real-time applications. Its benefits include scalability, rapid development, and a large, active community.

Prerequisites:

  1. A compatible Ubuntu version.
  2. sudo privileges (verify with sudo whoami).
  3. Basic familiarity with JavaScript and the command line.

Installation Methods:

We'll explore three distinct installation methods:

  1. Default Ubuntu Repositories: Simple, but may offer an older Node.js version.
  2. NodeSource Repository: Provides access to the latest stable releases.
  3. NVM (Node Version Manager): Recommended for managing multiple Node.js versions. Ideal for developers frequently switching versions.

Method 1: Default Ubuntu Repositories

This method is straightforward.

  • Update package lists: sudo apt update
  • Install Node.js and npm: sudo apt install nodejs (then sudo apt install npm if needed). Confirm with 'Y' when prompted.
  • Verify installation: node -v and npm -v should display version numbers.

Method 2: NodeSource Repository

This method ensures you have the latest Node.js version.

  • Add the NodeSource repository: (Consult the NodeSource GitHub page for the correct command based on your Ubuntu version. Typically involves curl or wget to download and execute an installation script).
  • Install Node.js and npm: sudo apt install nodejs
  • Verify installation: node -v and npm -v

Method 3: NVM (Node Version Manager)

NVM allows easy management of multiple Node.js versions.

  • Install NVM: (Follow instructions from the NVM GitHub repository's README. This usually involves downloading and running a script). Add export NVM_DIR="$HOME/.nvm" && [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" to your shell configuration file (e.g., .bashrc). Restart your terminal.
  • Select and install a Node.js version: nvm install --lts (for the latest LTS version).
  • Set default version: nvm alias default <version></version>
  • Switch between versions: nvm use <version></version>
  • Uninstall a version: nvm uninstall <version></version>

Uninstallation:

  • Using apt: sudo apt remove nodejs (if installed via Method 1 or 2).
  • Using NVM: nvm uninstall <version></version> (after deactivating with nvm deactivate).

Summary:

This guide provides three robust methods for installing and managing Node.js on Ubuntu. Choose the method that best suits your needs and experience level.

FAQs:

  • Node.js installation on Ubuntu 20.04 LTS: See the detailed instructions within the main article.
  • Verifying sudo privileges: Run sudo whoami.
  • Switching between NVM-installed versions: Use nvm use <version></version>.
  • Uninstalling Node.js: Use apt or NVM as described above.

The above is the detailed content of Quick Tip: Install Node.js on Ubuntu. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template