A Raspberry Pi is a small Linux computer, and setting one up takes about half an hour. This guide sets it up headless, meaning without its own screen or keyboard: you prepare the card on your computer so the Pi joins your Wi-Fi by itself, then you control it from your computer. That's how most electronics projects use a Pi. If you'd rather use a screen, keyboard and mouse, the steps are the same, and you can skip the SSH part.
What you need
| Item | What to get |
|---|---|
| Raspberry Pi | A Pi 5 for anything demanding. A Pi 4 or Zero 2 W is fine for sensors and small servers. |
| Power supply | The official one for your model. A Pi 5 needs 5 V at 5 A (the 27 W USB-C supply). A Pi 4 needs 5 V at 3 A (the 15 W USB-C supply). |
| microSD card | 16 GB or bigger. 32 GB is a good size. A1 or A2 rated cards are quicker for an operating system. |
| Computer | Windows, macOS or Linux, with an SD card reader, to prepare the card and connect to the Pi. |
A weak power supply is the most common cause of a Pi that crashes or behaves strangely. On a Pi 5, a supply that can't give 5 A also makes the Pi limit how much current its USB ports can supply.
1. Write the card with Raspberry Pi Imager
Download Raspberry Pi Imager from raspberrypi.com/software and install it. Put the microSD card in your computer and open Imager. It takes you through a series of steps:
- Device: choose your Pi model.
- OS: choose Raspberry Pi OS. The version marked as recommended includes a desktop. For a Pi without a screen, Raspberry Pi OS Lite (under Raspberry Pi OS (other)) is smaller and quicker.
- Storage: choose your microSD card. Check carefully: everything on the card will be erased.
- Customisation: this is the important part for a headless Pi. Set a hostname (the Pi's name on your network, for example
pi), your location, time zone and keyboard, a user name and password, and your Wi-Fi name and password. Then turn on SSH with password login. - Writing: check the summary and write the card. Imager checks it afterwards.
2. First boot
Put the card in the Pi and plug in the power. The first boot takes a few minutes, because the Pi expands its file system to fill the card and applies your settings. It may restart on its own during this.
3. Connect with SSH
SSH lets you type commands on the Pi from your computer. Windows 10 and 11, macOS and Linux all have it built in. Open a terminal (on Windows, PowerShell or Terminal) and type, using your own user name and hostname:
ssh yourname@pi.local
The first time, it asks whether you trust the Pi's fingerprint: type yes. Then enter your password. The prompt changes to show you're on the Pi.
If pi.local isn't found, look for the Pi in your router's list of connected devices and use its IP address instead, for example ssh yourname@192.168.1.60.
4. Update it
Bring all the software up to date before you start a project:
sudo apt update
sudo apt full-upgrade
The first command fetches the list of new versions, and the second installs them. Type y if it asks. If the update included a new kernel, restart with sudo reboot. sudo runs a command as the administrator, so it may ask for your password.
5. Turn on the interfaces your project needs
Run sudo raspi-config and open Interface Options to turn on I2C, SPI or 1-Wire for sensors that use them. Our temperature logger project uses 1-Wire, for example. Plain GPIO pins need nothing turning on.
6. Shut it down properly
Don't just pull the plug. If the Pi is writing to the card at that moment, the card can be corrupted. Type:
sudo shutdown now
Wait until the green activity light stops flashing, then unplug it. A Pi 5 also has a power button: pressing it starts a clean shutdown (on the desktop version a menu appears, and a second press confirms), and pressing it again starts the Pi.
Useful commands
| Command | What it does |
|---|---|
hostname -I | Shows the Pi's IP address |
ls, cd, nano file.py | List files, change folder, edit a file |
python3 file.py | Run a Python program (Ctrl+C stops it) |
vcgencmd measure_temp | Shows the processor temperature |
vcgencmd get_throttled | throttled=0x0 means no power or overheating problems since it booted |
sudo reboot | Restarts the Pi |
Our Linux command line basics guide covers many more.
Troubleshooting
- The Pi never appears on the network: check the Wi-Fi name and password in Imager (both case-sensitive), and that your location is set. A Zero 2 W only uses 2.4 GHz Wi-Fi. If it still won't connect, write the card again.
- "Connection refused" from SSH: SSH wasn't turned on. Write the card again with SSH turned on in the customisation step.
- "Host key verification failed": you've rebuilt the card, so the Pi has a new fingerprint. Remove the old one with
ssh-keygen -R pi.localand connect again. - Random crashes or a lightning-bolt warning: the power supply can't keep up. Use the official supply for your model.
Next steps
Learn to control the pins with our GPIO Zero guide and the pinout, then build a motion-activated light or a temperature logger with a web page.
Sources
The main references behind this guide. Numbers we worked out ourselves, such as the code outputs, come from running the code.