In this tutorial I will show you how to install Ubuntu MATE 18.04 on a Raspberry Pi 3 B+ board.
You’ll see how to configure everything step by step.
Why Ubuntu on a Raspberry Pi 3 B+?
The main supported OS for Raspberry Pi is Raspbian, an OS based on Debian, and adapted to the Raspberry Pi hardware.
So, why would you want to use Ubuntu?
- If you work with ROS (Robot Operating System), you know that the main supported OS is Ubuntu (at least for ROS 1.0)
- You may simply already use Ubuntu in your computer and some web servers, and you want to work on the Pi while keeping the same environment.
- Or you are just curious about trying new stuff!
In this tutorial we’ll use Ubuntu MATE. Why MATE? Well, it runs the same Ubuntu as the “standard” Ubuntu, just with a different desktop environment. Plus, it’s nicely packaged for Raspberry Pi.
Download the Ubuntu MATE image for Raspberry Pi 3 B+
First you have to download the OS image. Go to the download page of the Ubuntu MATE website.
Choose “Raspberry Pi for aarch32 (ARMv7) computers”
and then select Bionic Beaver (name for Ubuntu 18.04 release).
You can now download an archive of the image (.xz extention).
Flash the image into a micro SD card
micro SD card requirements
Make sure you get a class 10 micro SD card. You can see the class of the card when you buy it. The class is related to the writing speed. As your SD card will serve as the complete OS for your Raspberry Pi 3 B+, you want something that is fast enough.
Your micro SD card should also have at least 8GB of space. This is the bare minimum, I advise you take a bigger card (16 or 32GB).
Extract the Ubuntu MATE image
OK, you have a micro SD card. Now you need to flash the image into this card.
Warning: don’t flash the archive – .xz file, first you need to extract it! (might sound obvious but the first time I used a Raspberry Pi I made this mistake)
To extract a .xz file, use:
- 7-zip or a similar software on Windows. Right-click on the image > extract here.
- On Linux, use unxz:
unxz file.img.xz(if you don’t have unxz installed:
sudo apt install xz-utils)
Flash the image
To flash the image I recommend you use the open source Etcher software. This is a very handy multi-platform software for flashing SD cards.
Download Etcher and launch the software (no installation needed). Insert your micro SD card into your computer.
Then, all you need to do is select the image you just downloaded + extracted, and the SD card. Then, click on “Flash!” and wait a few minutes.
Even if the image size is much lower than the actual SD card size, don’t worry: when installing, the image will expand to take all the available space.
First steps with Ubuntu MATE 18.04 on Raspberry Pi 3 B+
Once the micro SD card is flashed with the image, remove it from your computer and insert it into your Raspberry Pi 3 B+.
Plug a screen with either the HDMI port, or the special port for Raspberry Pi compatible screens. Also plug a mouse and a keyboard. With that, you’ve got a complete computer!
You can now power on the Raspberry Pi 3 B+ with a micro USB charger (a phone charger is perfect for that).
The Raspberry Pi will boot.
Basically on the first boot you’ll just have to follow standard Ubuntu installation instructions:
- Choose your language.
- Choose your keyboard layout.
- Connect to a Wi-Fi network (strongly recommended).
- Choose your location.
- Choose whether you want to login automatically or not.
- Wait for the configuration and installation process. This might take a while. The system may also reboot.
Once the installation done and the Pi has reboot (do it manually if it didn’t), you might want to upgrade the Ubuntu packages on the system, because they won’t be up to date.
Open a terminal (to do that: click on the menu > type “terminal” and choose “MATE terminal”). On the terminal execute the following commands – might also take a long time:
$ sudo apt update ... $ sudo apt autoremove ... $ sudo apt upgrade ... $ sudo reboot
Once all the previous steps are done, basically one of the first things you want to do is to activate ssh, so you can control your Raspberry Pi 3B+ from your own computer, without an extra screen and keyboard.
On the Pi open a terminal and type:
$ sudo apt install openssh-server $ sudo systemctl enable ssh.service $ sudo systemctl start ssh.service $ sudo dpkg-reconfigure openssh-server
First we install openssh-server (it’s surely already installed, in this case you’ll just have a message saying so), and then we enable the ssh service (from systemd), so every time the Raspberry Pi 3 B+ boots it will launch the ssh server. Running dpkg-reconfigure will fix an error where you’d have a connection refused on the client, when trying to connect to the server.
Now you need to test if ssh is working correctly. To do that, your computer and Raspberry Pi 3 B+ must be connected to the same Wi-Fi network.
In a Raspberry Pi terminal type
hostname -I to know its IP address on the network.
$ hostname -I 192.168.1.145 # for example
On your computer, you can now try to connect to the Pi via ssh.
- On Windows, download, install, and open Putty (there is no ssh client by default on Windows). Connect to the IP address you got on the Pi. The username will be the username that you chose during the installation, and same thing for the password.
- On Linux, simply open a terminal, and type
ssh username@ip. You will be asked for the password. On success, you’ll see a welcome message.
$ ssh firstname.lastname@example.org email@example.com's password: Welcome to Ubuntu 18.04.2 LTS (GNU/Linux 4.15.0-1037-raspi2 armv7l) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage 0 packages can be updated. 0 updates are security updates. Last login: Mon Jun 17 08:26:59 2019 from 192.168.1.145 ed-pi@ed-pi-desktop:~$
You can now use your Raspberry Pi 3B+ without a screen, only with ssh!
Note: to exit from an ssh session, simply type
exit. This won’t shutdown the Pi, it will just log you out of the Pi.
Shutdown the Raspberry Pi 3B+ via ssh
It’s important to correctly shut down the Pi after you use it. You certainly don’t pull the plug to shut down your own computer/laptop (well I hope you don’t).
To shutdown your Pi with Ubuntu MATE you have 2 solutions:
- Use the desktop interface and shutdown via the menu, or
- Execute the
sudo shutdown nowcommand via ssh.
After you’ve configured ssh and you’ve shutdown the Pi correctly, you can remove any screen, keyboard, mouse. Restart the power so the Raspberry Pi 3 B+ will boot again, this time without the desktop environment (no screen is detected). You can now use your Pi 100% with ssh.
Of course this will be easier to use ssh after your Pi is connected to a Wi-Fi network.
Warning: if you abruptly shut down the Pi, you might corrupt the SD card. If the card is corrupted, well you’ll probably have to install everything again!
What to do next with Ubuntu MATE on your Raspberry Pi 3 B+
Now that Ubuntu MATE 18.04 is installed on your Pi, and that you can use ssh to control it, it’s time to go to the next step!
Here it really depends on what you want to do with it. For example, if you want to experiment on robotics applications (what this website is about):
- Setup and configure an IDE to edit files and write code. Some popular IDE for Raspberry Pi: Nano, Vim (check out how to install Vim on Raspberry Pi), Emacs
- Install ROS (Robot Operating System) to create scalable and powerful robot applications
- Experiment with GPIOs using the RPi.GPIO Python library or the WiringPi Cpp library.
- Learn how to make your programs automatically start on boot