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:
=== "x86_64"
bash
sudo apt update
sudo apt install -y nodejs npm
=== "arm/aarch64"
bash
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:
-
Add the NodeSource Repository: Choose the desired Node.js version. Replace
setup_18.xwith the specific version you want (e.g.,setup_16.xfor Node.js 16 orsetup_20.xfor Node.js 20).bash curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - -
Install Node.js:
bash sudo apt install -y nodejs -
Verify the Installation:
bash 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:
-
Install
nvm:Download and run the installation script for
nvm:bash sudo apt install curl curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash -
Load
nvmin 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: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 nvmThen reload your shell:
bash source ~/.bashrc -
Install a Specific Version of Node.js:
For example, to install Node.js 18:
bash nvm install 18 -
Switch Between Installed Versions:
To use a specific version of Node.js:
bash nvm use 18 -
Set a Default Version:
To set a default Node.js version:
bash nvm alias default 18 -
Verify the Installation:
bash 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.