Skip to content

Node.js on ChromeOS

Node.js is a powerful and widely-used runtime environment that allows you to run JavaScript on the server side. It is ideal for building scalable network applications, creating APIs, and developing web servers. Its lightweight, event-driven model makes it a favorite for modern application development.

With the integration of Linux (Crostini) on ChromeOS, Node.js can be easily installed and used on Chromebooks, enabling developers to build and test applications directly on their devices. This guide provides step-by-step instructions to set up Node.js on your ChromeOS device, along with npm (Node Package Manager) for managing packages and dependencies.

Whether you're starting with JavaScript development or you're an experienced developer looking to work on a lightweight, portable device, this tutorial has you covered. Let’s transform your Chromebook into a versatile development environment for Node.js. It is strongly recommended to also set up Git for source control management and Visual Studio Code as your code editor.

Installing Node.js on ChromeOS

Installing via Debian Repositories (Default)

If you prefer a stable but potentially older version, you can use the Node.js package available in the Debian repositories:

sudo apt update
sudo apt install -y nodejs npm
sudo apt update
sudo apt install -y nodejs npm

Installing the Latest Node.js from NodeSource

For the latest version of Node.js, install it from the NodeSource repositories. Follow these steps:

  1. Add the NodeSource Repository: Choose the desired Node.js version. Replace setup_18.x with the specific version you want (e.g., setup_16.x for Node.js 16 or setup_20.x for Node.js 20).

    curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
    
  2. Install Node.js:

    sudo apt install -y nodejs
    
  3. Verify the Installation:

    node -v
    npm -v
    

Installing and Using nvm (Node Version Manager)

nvm is a tool that allows you to easily install and manage multiple versions of Node.js. Here's how to set it up:

  1. Install nvm:

    Download and run the installation script for nvm:

    sudo apt install curl
    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
    
  2. Load nvm in Your Shell:

    If not using the bash shell, you may need to add the following line to your shell configuration file (~/.zshrc, or similar) This is done automatically on bash:

    export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
    [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
    

    Then reload your shell:

    source ~/.bashrc
    
  3. Install a Specific Version of Node.js:

    For example, to install Node.js 18:

    nvm install 18
    
  4. Switch Between Installed Versions:

    To use a specific version of Node.js:

    nvm use 18
    
  5. Set a Default Version:

    To set a default Node.js version:

    nvm alias default 18
    
  6. Verify the Installation:

    node -v
    npm -v
    

Why Use nvm?

  • Flexibility to work with different Node.js versions for various projects.
  • Avoids conflicts with system-wide installations.
  • Easy to update and switch between versions.