Rebecca Murphey

Last updated

Raspberry Pi setup notes

The holidays are the perfect time for setting up a Raspberry Pi, screwing it up, and having to start over again. I’ve done this enough times in the last two weeks that I decided to write some stuff down.

Of note:

Set up for headless use #

Before you put the SD card in the Pi, set it up so it will connect to wifi and you can connect to it via ssh. With the SD card still connected to the Mac:

cd /Volumes/boot
touch ssh

Set up wifi by creating the file wpa_supplicant.conf in /Volumes/boot, with the following contents:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
country=<2 letter ISO 3166-1 country code>


The country code for the US is US. (See other country codes.)

Connect & update & install an editor #

Figure out the Pi’s IP address.

nmap -sn

Then, ssh to it:

ssh [email protected]

Enter raspberry as the password, and you’ll be logged in.

Change the password for the pi user:


You’ll hardly ever use this password, and maybe you’ll never use it, but if you do need to use it, you probably won’t remember it, and you’ll end up reading this blog post when you re-image your Pi.

Update package lists, upgrade packages (this could take a while), and install vim (if you don’t want to use nano).

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install vim

Create a new user #

Create a new user with sudo permissions:

sudo adduser rmurphey
sudo adduser rmurphey sudo

You’ll be prompted for a password. You’ll need to use this password every time that you sudo from the new account, which should make it more likely that you’ll remember it, but if your Pi use is seasonal like mine, good luck with that. I’m not saying you should write it down, but … you do you.

You could use this password to log in to your Pi, but that would be a pain. Instead, copy an ssh key from your Mac to the Pi so you can log in without a password:

ssh-copy-id [email protected]

Oh My ZSH #

Oh My ZSH is nice. Set it up.

sudo apt-get install zsh
sh -c "$(curl -fsSL"

I like the fino theme.

Python 3 #

If you want to interact with devices connected to your Pi, you’ll probably end up using Python. Set up Python 3 as the default Python. Why isn’t it already? Who knows.

sudo pip3 install --upgrade setuptools
sudo apt-get install -y python3 git python3-pip
sudo update-alternatives --install /usr/bin/python python $(which python2) 1
sudo update-alternatives --install /usr/bin/python python $(which python3) 2
sudo update-alternatives --config python

Use sudo raspi-config to enable I2C and SPI.

Install some libraries for interacting with devices:

pip3 install RPI.GPIO
pip3 install adafruit-blinka

It seems like only the pi user has access to the SPI, I2C, and GPIO interfaces by default, so:

sudo adduser rmurphey spi
sudo adduser rmurphey gpio
sudo adduser rmurphey i2c

You might need to log out and log back in for these permissions changes to take effect.

Node #

JavaScript is fun, and johnny-five is a fun way to use JavaScript, so you’ll want Node.

Install with nvm:

curl -o- | bash

Read the output; you’ll need to add something like this to .zshrc:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/" ] && \. "$NVM_DIR/"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

Finally, install the version you want:

nvm install 14

Maybe #

Couldn’t I just save a copy of the SD card before I screw it up again? #


Read more posts in the archive.