如何在Raspberry Pi B+上安装Node.js?安装遇阻求教程与解决方案
Hey there, I’ve fought through the same Node.js install headaches on a Pi B+ before—let’s get this sorted out for you. The biggest gotcha here is that the Pi B+ uses an ARMv6 architecture, which newer Node.js versions (18+) no longer support. Here’s a step-by-step breakdown that should work reliably:
First: Update Your System (Critical!)
Always start here to avoid dependency conflicts that cause random errors:
sudo apt update && sudo apt upgrade -y
Option 1: Install LTS Node.js 16.x (Last ARMv6-Supported Official Release)
This is the simplest method for most users. Node.js 16.x is the last LTS version that works natively on ARMv6:
- Add the NodeSource repository for 16.x:
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash - - Install Node.js and npm:
sudo apt install -y nodejs - Verify the install worked:
You should see version numbers likenode -v && npm -vv16.20.2and8.19.4if it worked.
Option 2: Use nvm (Flexible Version Management)
If you need to switch between Node versions later, nvm is your best bet. It handles architecture compatibility automatically:
- Install nvm:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash - Restart your terminal, or reload your bash profile to activate nvm:
source ~/.bashrc - Install the latest supported ARMv6 version (we’ll use LTS 16.x here):
nvm install lts/gallium - Set it as your default version:
nvm alias default lts/gallium - Verify:
node -v && npm -v
Fixing Common Errors You Might Hit
- "Architecture not supported" error: You tried installing a version newer than 16.x. Stick to 16.x or earlier—newer Node builds drop ARMv6 support entirely.
- npm permission errors: Never use
sudoto install npm packages (it causes permission messes). Instead, configure npm to use your user directory:mkdir ~/.npm-global npm config set prefix '~/.npm-global' echo "export PATH=~/.npm-global/bin:$PATH" >> ~/.bashrc source ~/.bashrc - Missing dependencies during install: If you get errors about
libssl-devor build tools, install these first:sudo apt install -y build-essential libssl-dev
If you’re still hitting specific error messages (like a particular code or warning), drop them in a comment and I’ll help you troubleshoot further!
内容的提问来源于stack exchange,提问作者circl




