How to Install Node.js and NPM in Termux

Updated August 2026 · Tested on Android + Termux

Running JavaScript directly on your phone used to mean clunky browser workarounds or rooting your device. Termux changes that — it turns Android into a real Linux terminal, and once Node.js is installed, your phone becomes a legitimate, pocket-sized dev environment.

Install Node.js and NPM in Termux on Android phone illustration

Quick answer: if you only want the commands, jump to "Quick Version" below. Everything else — troubleshooting, error fixes, best practices — is there for when something breaks, which it eventually will.

How this guide was put together: every command below was tested directly in Termux on Android, not copied from documentation. Where an error is common but not obvious (like permission or storage errors), it's included with the actual fix, not a generic troubleshooting link.

Quick Version: Just Give Me the Commands

Open Termux and run these one by one:

pkg update && pkg upgrade -y
pkg install nodejs -y
node -v
npm -v

This refreshes Termux's package list, installs the latest Node.js (NPM comes bundled in), then prints both version numbers to confirm it worked.

Quick Comparison

Command What It Does
pkg update && pkg upgrade -yRefreshes package lists and updates existing tools
pkg install nodejs -yInstalls the latest Node.js + NPM
pkg install nodejs-lts -yInstalls the stable LTS version instead
node -v / npm -vConfirms your installed versions

Before You Start

  • Get Termux from F-Droid or GitHub — the Play Store version is discontinued and its package links are broken.
  • Use a stable connection. A weak signal mid-download is the most common cause of a corrupted install.
  • Free up ~500MB of storage before you start, so Node, NPM, and your packages have room.
  • Grant storage access if you'll work with local files:
termux-setup-storage

Step 1: Update Termux First

This is the step most people skip — and usually why the install breaks later.

pkg update && pkg upgrade -y

pkg update syncs your package list with Termux's servers; pkg upgrade -y brings everything already installed up to date.

Step 2: Pick Current or LTS

Current build — newest features, best for experimenting:

pkg install nodejs -y

LTS build — stable, better for anything you'll keep running:

pkg install nodejs-lts -y

Don't install both — they'll overwrite each other's binaries.

Step 3: Confirm It Installed

node -v
npm -v

Both commands should print a version number with no errors.

Run Your First Script

1. Create a file:

cat > test.js

Paste this in, then press CTRL + D to save:

console.log("Hello from Node.js inside Termux!");
console.log("Server environment is working perfectly.");

2. Run it:

node test.js

Installing Packages with NPM

Start a project:

mkdir my-app && cd my-app
npm init -y

Install a library:

npm install express

Prefer Yarn? Once Node is installed:

pkg install yarn -y
yarn -v

Fixing the "Node Version Error" in Termux

This is the error that frustrates almost everyone eventually — usually from old packages, outdated global modules, or a broken mirror.

Common causes: outdated package mirrors, corrupted NPM cache, native C/C++ modules that don't match Android's Bionic library, or global packages built for an older Node version.

Fix 1 — Switch mirrors and reinstall:

termux-change-repo

Pick "All mirrors" in the popup, then:

pkg update && pkg upgrade -y
pkg reinstall nodejs -y

Fix 2 — Clear the NPM cache:

npm cache clean --force
rm -rf ~/.npm
rm -rf node_modules package-lock.json
npm install

Fix 3 — Install build tools for native modules:

pkg install build-essential python binutils -y

Then run npm install again — this fixes most node-gyp compile errors.

Fix 4 — Switch to LTS:

pkg uninstall nodejs
pkg install nodejs-lts -y

Other Errors You Might Run Into

"EACCES: permission denied" when installing global packages — point NPM to a folder you own instead of using sudo (which Termux doesn't really support):

mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
export PATH=~/.npm-global/bin:$PATH

"ENOSPC: no space left on device" — usually Termux's internal partition, not your phone's actual storage:

npm cache clean --force
pkg clean
pkg autoclean

Network timeout during npm install — usually your carrier or Wi-Fi throttling the registry. Try switching between mobile data and Wi-Fi, or a different registry mirror.

A Few Best Practices

  • Don't run as root. Termux is sandboxed on purpose.
  • Watch your storage. node_modules folders grow fast — run npm cache clean --force now and then.
  • Use PM2 for background servers:
npm install -g pm2
pm2 start app.js

Frequently Asked Questions

Can I install an old Node version like Node 12 or 14?

Termux's official repos only keep active releases (nodejs and nodejs-lts). For older versions, use nvm or a full Linux distro inside Termux via PRoot.

Why do I get node-gyp errors when installing a package?

node-gyp needs a compiler and Python to build native add-ons. Run pkg install build-essential python -y and try again.

Does installing Node.js also install NPM?

Yes — both nodejs and nodejs-lts come bundled with NPM automatically.

Can I access a Node.js server from my phone's browser?

Yes. With your server running on, say, port 3000, open localhost:3000 on the same device. From another device on the same Wi-Fi, use your phone's local IP instead of localhost.

How do I fully remove Node.js and NPM from Termux?

pkg remove nodejs nodejs-lts -y
rm -rf ~/.npm ~/.node-gyp