How to install Ubuntu Server on your Raspberry Pi

Key Value
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.
Categories iot, raspberrypi
Difficulty 2
Author Oliver Smith oliver.smith@canonical.com

Overview

Duration: 2:00

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!

ā“˜ Join us on YouTube to learn more about Ubuntu for Raspberry Pi

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

And optionally:

  • 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

Duration: 5:00

:warning: Warning
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 latest Ubuntu 22.04 LTS server for 64 bit architectures. As indicated in the imager this will work for the Raspberry Pi 3, 4 and Zero 2 W.

Select the image and open the ā€œChoose Storageā€ menu. Select the microSD card you have inserted.

Before clicking ā€˜Writeā€™ to flash your SD Card, click the cog icon to open a settings menu for advanced options.

Using Advanced Options

Duration: 3:00

The Advanced options menu allows you to preconfigure a variety of network settings that would previously have required manual editing after flashing the SD card.

Here you can define the hostname of your Raspberry Pi and enable SSH, allowing you to connect to your Pi remotely.

Note: We recommend setting SSH to use password authentication to make connecting remotely simpler. If you are interested in using public-keys with SSH you can read more about them here.

You can also configure your wi-fi connection in this menu, adding your SSID (wi-fi name) and Password. This will allow your Raspberry Pi to automatically connect to the internet as soon as the device starts. If you are connecting your Raspberry Pi to the internet via an ethernet cable, you can skip this step.

Once you have entered your details, click ā€˜Saveā€™ and then ā€˜Writeā€™ to flash your SD card!

Eject your SD card and insert it into your Raspberry Pi to continue to the next step.

Boot Ubuntu Server

Duration: 2:00

If you are using an HDMI screen and a USB keyboard, ensure they are plugged in before powering on the Pi. You will be able to see the boot process on the screen.

:warning: Warning
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 the username and password you entered in the Advanced Setting menu. After a minute or so, Ubuntu on your Raspberry Pi will have fully booted and connected to the network.

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

The easiest way to determine your Raspberry Piā€™s IP address is by opening the dashboard for your wifi router and looking for connected devices. If you set a hostname in the ā€˜Advanced optionsā€™ this should appear as your device name.

If you donā€™t have access to your router dashboard you can temporarily connect a monitor and keyboard to your Raspberry Pi and run:

hostname -I

Which will return your deviceā€™s IP (Note: in this case the command uses the actual word ā€˜hostnameā€™, not the hostname you defined in Advanced options!).

Using an SSH client

On Ubuntu and Mac OS, an SSH client is already installed. If you are on Windows you can either use Ubuntu on WSL or the built-in SSH client in the Windows terminal.

Open a terminal and run the following command:

ssh <username>@<Raspberry Piā€™s IP address>

or

ssh <username>@<hostname>

If you set one up in the Advanced options menu.

You will be asked to confirm the connection:

Are you sure you want to continue connecting (yes/no/[fingerprint])?

Type ā€œyesā€ to confirm. You will then be asked to sign in with your username and password

ā“˜ Default users
If you did not create a username and password in the Advanced options menu, the username and password will both be ā€˜ubuntuā€™ by default and you will be asked to create a new password at this stage. 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 wi-fi.

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.

Run sudo netplan apply and sudo reboot and when you log back in, you will be connected to your wifi.

Install a desktop

Duration: 10:00

ā“˜ 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:

sudo reboot

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!

3 Likes

I recommend adding a step to this tutorial to have users run:

sudo apt-get update
sudo apt-get upgrade

prior to attempting to install a desktop. When I first tried to load a desktop, the install failed, but it did suggest running those two commands. I did so, then re-ran the installation of the desktop, and it worked.

Very good point, thanks for catching this, Iā€™ve updated the tuto.

1 Like

Hi,
I have been trying to install Ubuntu Server 18.04 on my Raspberry Pi. I am ok until until I get to booting the Ubuntu server. The boot up process asks for a login and password. The tutorial mentions using ubuntu as password, but what do I use for a login ID?

Hi kvemuri, you can use ubuntu for both the login ID and the password. Thatā€™s a good catch though thank you. I have now included that in the tutorial :slight_smile:

1 Like

Hi Rhys-Davies,

under getting ā€œsetup with wi-fiā€, I do not have a file entitled network-config within the system boot partition on the SD card.

Far more to the point, however, how may I install Ubuntu server on my Raspberry Pi with a static IP?

Hi colossal,

If you donā€™t have the file you might be using the wrong image or be looking in the wrong place. Iā€™d advise going through the process again, and make selections with extra care. If the problem still persists let us know, I believe a static/dynamic IP is router specific, so the install process should be the same.

Some versions of Windows 10 include an SSH client accessible through the Command Prompt.

1 Like

Thanks for letting us know Phil, Iā€™ve made the edit :slight_smile:

Thereā€™s typo in the above part:
ā€œRapsberryā€ ā†’ ā€œRaspberryā€

Heck, that oneā€™s embarrassing, thanks for catching it :slight_smile:

Hello,
Was there a change of login and password ?
I followed all the instructions (ethernet cable set) once I power my raspberry, after 1 minute I get ā€œubuntu loginā€.
I enter ā€œubuntuā€ as login
Then I get ā€œpasswordā€
I canā€™t write anything, doesnā€™t work
I press enter and I get :
ubuntu login incorrect
ubuntu login :

I am very sorry to annoy you but I havenā€™t found any answer on forums.
I am stuck with this situation, canā€™t write anything without being asked for the ubuntu login and its password.
Thank you for your help.

I couldnā€™t find the user name and password for the new server install.
i found it on the web
but would be nice to have it here.
for the rest the install and instructions are great
thanks

Hi presistent-cc, first let me say this is not annoying at all, this is exactly what this forum is for, Iā€™m sorry for taking so long to get back to you.

To your question, this is a known issue. The login and password is still ā€˜ubuntuā€™ for both. However when you are asked for those credentials there is still some code running in the background. Until its finished you wonā€™t be able to log in. Unfortunately there isnā€™t a fix for this yet, although we are working on it. Fortunately, if you wait a few more minutes, the process will finish running and you will be able to log in. Sorry for the inconvenience, as I say, we know about it and are working on it. Once you wait it out this first time though every subsequent time you will be bale to login without the wait.

1 Like

Hi wisdomlight, thanks for your comment, although Iā€™m not sure I understand what you mean. The user name (here noted as login ID) and password are both listed here, they are ā€˜ubuntuā€™ for both.

yes but somehow they werenā€™t that clear.
i think it would have been easier to have them somewhere earlier.
maybe it is a redundant point.

also after doing passwordless ssh i went on and i installed kubuntu. Then the machine did not boot. It started the boot process I could see many things happening all with green ok and then there where three lines and the 4th was a prompt and nothing happened. strange.

So I re wrote the SD card today and ubuntu with ubuntu did not work!

I am going to re try.
Cheers
then I re installed the ubuntu server

1 Like

Again the same problem occurred with installing kubuntu in Rpi 4 that had a successful installation of Ubuntu 20

3 Likes

You might want to add dc:a6:32 too when looking for IP address via arp.

Hello, Thank you for your reply. I tried again and waited 15 minutes. It didnā€™t solve the problem. I canā€™t write anything when I get to the step ā€œpasswordā€. I send you screenshot enclosed. (I used a Raspberry pi 3B brand new, a 64Gb SD card and Ethernet cable).


Thank you for your help.

Having the same exact problem here. Would love to understand what exactly it is I have to do to get it working.

Same thing: Followed Ubuntuā€™s tutorial for RPi4 and Ubuntu 20 installed successfully. So I typed sudo reboot and waited for awhile and it got here and just hung. Forever. I have no idea what to do now.