For many Raspberry Pi projects, you don’t need or want a GUI to load in order to save resources. It can be inconvenient to connect a new device to an HDMI display, keyboard and mouse.
Installing an OS and connecting to a headless Raspberry Pi 3 B+ or Zero W is very easy. In addition to the board and cord, you’ll need:
- SD card reader – $16 at Amazon
- A fast SD card:
- Fast: Samsung EVO Select 32GB ($7)
- Faster: Samsung EVO Plus 32GB – ($9.50)
- Fastest: SanDisk Extreme Pro 32GB – ($15)
- Operating system image – This article uses Raspbian Stretch Lite
- balenaEtcher – Free software by balena
- A text editor and SSH client (shout out to Termius)
Installing Raspbian
To begin, write the Raspbian Lite operating system to your micro SD card.
- Plug in your micro SD into a desktop computer and open balenaEtcher
- Select an image, the destination micro SD card, then click Flash! (If you micro SD is larger than 32gb, you will get a warning about it being “unusually large.” Ignore it and continue.)
When finished, we need to modify the contents of the SD card. If you don’t see it, you may need to re-mount the micro SD card first. You can usually do this by unplugging and re-plugging in your SD card reader. On Mac OS X, I use Disk Utility to re-mount it.
Configuring Wi-Fi & Enabling SSH
To enable SSH connectivity, simple add an empty file named ssh to the root of the micro SD card.
To configure wi-fi, create a file named wpa_supplicant.conf with the following content, changing your country code, wi-fi SSID and password as appropriate:
country=US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="YOUR_WIFI_SSID"
scan_ssid=1
psk="YOUR_WIFI_PASSWORD"
key_mgmt=WPA-PSK
}
When finished, unmount the micro SD card, insert it into your Pi and power it on. You should be able to SSH to its IP address – the default credentials:
- Username: pi
- Password: raspberry
If you’re having trouble finding the IP address of your Pi, you can use arp-scan on Linux and Mac OS to list devices on your subnet.
On Mac OS X, install Homebrew if you don’t already have it, then:
brew install arp-scan
sudo arp-scan -l
Installing Latest Node.js
Find and download the latest stable version for ARMv6:
https://nodejs.org/en/blog/release/
cd ~
wget https://nodejs.org/dist/v10.15.0/node-v10.15.0-linux-armv6l.tar.xz
# Extract the archive
tar xf node-v10.15.0-linux-armv6l.tar.xz
# Copy the binaries
cd node-v10.15.0-linux-armv6l
sudo cp -R bin/* /usr/bin/
sudo cp -R lib/* /usr/lib/
# Verify versions
node -v
npm -v
npx -v