|Summary||A complete guide to installing Ubuntu Server on your Raspberry Pi 4, 3 or 2 in a couple of minutes. In a headless setup or with a screen and with a Wi-Fi or ethernet connection.|
|Author||Canonical Web Team email@example.com|
In this tutorial, we walk you through the process of installing Ubuntu Server on a Raspberry Pi, connecting it to the internet and using it remotely. There are two setup methods in this tutorial: with an extra HDMI screen and USB keyboard for your Pi, or headless. Let’s start!
What you’ll learn
- How to create a bootable Ubuntu Server microSD card
- How to setup internet connectivity on the Raspberry Pi
- How to access your Raspberry Pi remotely
What you’ll need
- A microSD card (4GB minimum, 8GB recommended)
- A computer with a microSD card drive
- A Raspberry Pi 2, 3 or 4
- A micro-USB power cable (USB-C for the Pi 4)
- A Wi-Fi network or an ethernet cable with an internet connection
- A monitor with an HDMI interface
- An HDMI cable for the Pi 2 & 3 and a micro HDMI cable for the Pi 4
- A USB keyboard
Prepare the SD Card
Following these steps will erase all existing content on the microSD card.
First, insert the microSD card into your computer.
Now you need to install the right Raspberry Pi Imager for your operating system. You can do this with the following links:
Or, if you are on Ubuntu, you can run:
sudo snap install rpi-imager
Once this is done, start the Imager and open the “CHOOSE OS” menu.
Scroll down the menu click “Other general-purpose OS”.
Here you you can select Ubuntu and see a list of download options. For this tutorial we recommend you select the Ubuntu 20.04 download. As indicated in the imager this will work for the Raspberry Pi 2,3, 3+ and any of the 4’s.
Select the image and open the “SD Card” menu. Select the microSD card you have inserted.
Finally, click “WRITE” and wait for the magic to happen… (This magic might take a few minutes)
Wi-Fi or Ethernet
If you want to use your local lan’s DHCP server to get an IP address for your pi then there are two ways to get your Pi connected to the internet:
The first is to connect your Pi to your router with an ethernet cable. In this case, you can skip this step and go to the next one in the tutorial.
The second requires a local Wi-Fi network that both your computer and Pi can be connected to. We are going to edit files you just downloaded on your SD card to ensure your Pi can connect to the Wi-Fi network at boot.
If you want to have the Pi boot to a known IP address then see the section “Set a Static IP”.
Getting setup with Wi-Fi
With the SD card still inserted in your laptop, open a file manager and locate the “system-boot” partition on the card. It contains initial configuration files that load during the first boot process.
ⓘ Note: your system might look different from the screenshots here because this tutorial was written using Ubuntu 18.04 LTS. The steps are still the same even if things look a little different.
Note: Screenshots have been made on an Ubuntu desktop but it can be done on Windows and MacOS too
network-config file to add your Wi-Fi credentials. An example is already included in the file, you can simply adapt it.
To do so, uncomment (remove the “#” at the beginning) and edit the following lines:
wifis: wlan0: dhcp4: true optional: true access-points: <wifi network name>: password: "<wifi password>"
wifis: wlan0: dhcp4: true optional: true access-points: "home network": password: "123456789"
Note: network name must be enclosed in quotation marks.
Save the file and extract the card from your laptop.
Note ⓘ: During the first boot, your Raspberry Pi will try to connect to this network. It will fail the first time around. Simply reboot
sudo rebootand it will work.
Set a static IP
To set a static IP you need to replace the
line in the network-config file with lines that specify the intended IP address as well as its default gateway and DNS server. You can do this for either the eth0 or wlan0 interface (or both). It is important that you get the indenting right for this work correctly
For example, if you were planning to give the pi the address 192.168.1.17 in the 192.168.1.0/24 subnet with a default gateway of 192.168.1.1 and a DNS server of 192.168.1.53 then the following text would work. The same structure works for both the eth0 or wlan0 sections in the file:
ethernets: eth0: addresses: - 192.168.1.17/24 gateway4: 192.168.1.1 nameservers: addresses: [192.168.1.53] optional: true
Boot Ubuntu Server
If you are using an HDMI screen and a USB keyboard, ensure they are plugged in before powering the Pi. You will be able to see the boot process on the screen.
During your first boot a tool called cloud-init is doing configuration. WAIT for it to finish before trying to log in. It typically takes less than 2 minutes but there is a break between the log-in prompt and cloud-init completing. If you interrupt the process you have to start again. You’ll know it’s done when it outputs some more lines after the log-in prompt has appeared.
Once cloud-init finishes log in using “ubuntu” as both the password and login ID. After a minute or so, Ubuntu on your Raspberry Pi will have fully booted and connected to the network.
If you are using an ethernet cable and are not connected to the network at this point you may need to run:
sudo dhclient eth0
Connect remotely to your Raspberry Pi
To connect to your Raspberry Pi remotely, you need two things (we’ll help you find them):
- Its IP address on the local network
- An SSH client (SSH is a communication protocol between machines)
You have to do this if you are running your device headless, but you might also want to do this if you are not so you can access your Pi from anywhere.
Determining the Pi’s IP address
To determine the IP address of your board, open a terminal and run the
On Ubuntu and Mac OS:
arp -na | grep -i "b8:27:eb\|dc:a6:32\|e4:5f:01"
Depending on your version of Ubuntu, you may need to install the
net-toolspackage. Install it with
sudo apt install net-toolsand try the
arp -a | findstr b8-27-eb dc-a6-32 e4-5f-01
This will return an output similar to:
? (xx.xx.xx.x) at b8:27:eb:yy:yy:yy [ether] on wlp2s0
Where the x’s are the IP address of any Raspberry Pi connected to the local network. Note it down.
If the command doesn’t return an IP address, you may need to wait a little longer for your Pi to join the network. If you still can’t see it after a few tries, which can happen with some home or office network configurations, we recommend you use a USB keyboard and HDMI screen to interact with your device.
Using an SSH client
On Ubuntu and Mac OS, an SSH client is already installed. Some versions of Windows 10 also include an SSH client too, but if yours does not or you’re unsure, follow these steps to install one.
Open a terminal and run the following command:
ssh ubuntu@<Raspberry Pi’s IP address>
You will be asked to confirm the connection:
Are you sure you want to continue connecting (yes/no/[fingerprint])?
Type “yes” to confirm.
Changing the password
When prompted, use “ubuntu” for the password. (The cursor won’t move when you type the password.) The first thing Ubuntu will do is to ask you to change it to a secure password. Once done, you can reconnect again with the SSH command and the new password.
Success! You are now connected to Ubuntu Server running on your Raspberry Pi.
Still not connected to the internet?
Sometimes the structure of the network-config file that you modified before boot gets messed up when you boot. This would cause your Pi not to be able to connect to your wifi.
To fix this you need to go into the correct file and correct the issue. Run:
sudo nano /etc/netplan/50-cloud-init.yaml
so you can edit the file. Edit it so it looks like this again, the indentation needs to be correct for the .yaml to work:
wifis: wlan0: dhcp4: true optional: true access-points: "home network": password: "123456789"
Save and exit the file with
Ctrl + S and
Ctrl + X.
sudo netplan apply and
sudo reboot and when you log back in, you will be connected to your wifi.
Install a desktop
ⓘ Optional step
Depending on what you are going to use your Pi for, you may want a desktop environment to run graphical applications. Nevertheless, this step is completely optional.
First you need to ensure your packages are updated to the latest version, run:
sudo apt update sudo apt upgrade
Then, you can use the
apt install command to install a desktop environment.
Here are some popular and lightweight options:
sudo apt install xubuntu-desktop
sudo apt install lubuntu-desktop
If you run into issues with either of these check out this blog. We’re working on fixing this imminently.
Learn more about Ubuntu flavours.
Once the install finishes, reboot your pi with:
And your new desktop will come up automatically
Alternatively, if you now decide you want an Ubuntu Desktop proper, a full-fat version, you can head over to our other tutorial to re-flash your Raspberry Pi with the Ubuntu Desktop.
That’s all, folks!
You are done! Up and running on Ubuntu Server.
For more details about Raspberry Pi specific packages included with this image and further customisations, such as accelerated video drivers and optional package repositories, you can refer to the RaspberryPi wiki.
You also might want to install some software on your Pi. Ubuntu has extensive repositories available, that you can browse at packages.ubuntu.com. You can also use the snap command to install snap packages. The Snap Store is where you can find the best Linux open source and proprietary apps to install on your Raspberry Pi and get started with any project!
Automate provisioning of your Pis and build a cluster with MAAS
You can also explore MAAS which enables the automation of installing Ubuntu on machines. You can try out our special tutorial created specifically to enable you to build your own Raspberry Pi cluster!