Setup Ubuntu machine

post hero image

Table of Contents

Introduction

Here is a comprehensive list of pieces of software and tools you need to getting started with an Ubuntu-based Linux machine. Ubuntu uses apt as package manager.

Add user to sudo

It could happen that the current user has no root privileges. Every Linux machine has at least root user.

# login current terminal as root user ('sudo su' command could not work)
su - root

# add given user to sudo group
usermod -aG sudo <non-sudo-user>

# check which users have sudo permissions
getent group sudo

Run a Service at boot with systemctl

Running services at boot a common use of systemctl, especially in servers. You can tell a service to run at startup by typing:

sudo systemctl enable yourservice

If you need to disable a service:

sudo systemctl disable yourservice

If the service isn’t found, you may need to point to its direct file path with:

sudo systemctl enable /path/to/yourservice.service

However, this won’t work if the file isn’t on the root file system.

Tools

Balena Etcher

This tool allows you to write bootable SD card or USB drives starting from an .ISO file. It comes in help when working with Raspberry Pi or any Linux distributions.

curl -1sLf 'https://dl.cloudsmith.io/public/balena/etcher/setup.deb.sh' | sudo -E bash
sudo apt update
sudo apt install balena-etcher-electron

Docker Engine

Follow the official documentation: install engine on Ubuntu

# 1) set up the repository
# update the apt package index and install packages to allow apt to use a repository over HTTPS:
sudo apt update
sudo apt install -y ca-certificates curl gnupg lsb-release

# add Docker's official GPG key
# note that this command is specifically for Ubuntu
# replace "ubuntu" with "debian" in the string below to install the proper version
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
      $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

# 2) install Docker Engine
sudo apt update # update the apt package index

# if receiving a GPG error when running apt-get update, the default umask may be incorrectly configured, preventing detection of the repository public key file
# try granting read permission for the Docker public key file before updating the package index
sudo chmod a+r /etc/apt/keyrings/docker.gpg
sudo apt update

sudo apt install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin

Take care to follow Docker Engine post-installation steps to manage Docker as non-root user.

Edge Impulse

Edge Impulse is a development platform for machine learning on edge devices. It allows you to build advanced edge ML solutions and collecting.

# https://docs.edgeimpulse.com/docs/development-platforms/officially-supported-cpu-gpu-targets/linux-x86_64
sudo apt install -y curl
curl -sL https://deb.nodesource.com/setup_14.x | sudo bash -
sudo apt install -y gcc g++ make build-essential nodejs sox gstreamer1.0-tools gstreamer1.0-plugins-good gstreamer1.0-plugins-base gstreamer1.0-plugins-base-apps
npm config set user root && sudo npm install edge-impulse-linux -g --unsafe-perm

git

git is a VCS (Version Control System) created by Linus Torvalds, the same software engineer who developed the Linux kernel!

Version control systems is used to track changes in a directory over the time. Nowadays, they’re used to maintaining the history of all the software products’ codes. To allow several developer to work on the same code, a VCS must rely on platform like GitHub or GitLab where the code is uploaded and versioned.

The key features that a VCS must provide are:

  1. Maintain independent branches of code for team members
  2. Ease of comparison of code across different branches
  3. Merging of code from several branches of multiple team members
  4. Annotate changes with the name of author and message in a version of the code
  5. Simple comparison across versions
  6. Revert changes made to the code to any state from its history

To install git and its extension git-flow, you need to type:

# https://git-scm.com/download/linux
sudo add-apt-repository ppa:git-core/ppa
sudo apt update
sudo apt install -y git

# https://github.com/nvie/gitflow
sudo apt install -y git-flow

# Large File Support extension: https://git-lfs.github.com/
sudo apt install -y git-lfs

Configure global settings like email, name and commands colorization:

# set the email that will be attached to your commits
git config --global user.email "you@example.com"

# set the username that will be attached to your commits
git config --global user.name "Your Name"

# enable helpful colorization for command line output
git config --global color.ui auto

# set merge as git pull default polic 
git config --global pull.rebase false

# show the customized values
git config --global --list

Configure SSH client

It’s better to have a different pair of SSH keys foreach server (i.e. GitHub, GitLab, BitBucket, self-hosted, …) you connect to.

Let’s start:

cd ~/.ssh/

# generate a new key
ssh-keygen -t ed25519 -C "I am the key label"

It will output:

# Generating public/private ed25519 key pair.
# Enter file in which to save the key (/home/$USER/.ssh/id_ed25519):

If you accept the default files location, their names will contain the encryption algorithm name. If you need to use multiple SSH key, it’s better to have the provider’s name inside file names.

Specify the new name after : sign of the line above.

# /home/$USER/.ssh/id_[PROVIDER]

# Example: add GitLab.com SSH key
/home/$USER/.ssh/id_gitlab

You can also rename the files later on. Remind to rename both the private and public keys:

# mv id_[ALGORITHM] id_[PROVIDER]
# mv id_[ALGORITHM].pub id_[PROVIDER].pub

Once you have both private and public keys, you’re read to start ssh-agent in background:

eval "$(ssh-agent -s)"

# add your SSH private key to the ssh-agent
ssh-add id_gitlab
# ssh-add id_[PROVIDER]

# show the content to copy
cat id_gitlab.pub
# cat id_[PROVIDER].pub

Copy the public key and add in the right place inside the website of the server provider.

Here are the most used git providers’ guides:

Create a configuration file foreach server provider you need, even the self-hosted ones.

nano config

My config file looks like

Host github.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_github
  IdentitiesOnly yes

Host gitlab.com
  HostName gitlab.com
  User git
  IdentityFile ~/.ssh/id_gitlab
  IdentitiesOnly yes

Host bitbucket.org
  HostName bitbucket.org
  User git
  IdentityFile ~/.ssh/id_bitbucket
  IdentitiesOnly yes

Configure SSH remote access

By default, when Ubuntu is first installed, remote access via SSH is not allowed.

sudo apt update -y

# install the package
sudo apt install -y openssh-server

# it should start automatically, check with:
sudo systemctl status ssh

# if the firewall is enabled, make sure to open the SSH port
sudo ufw allow ssh

# should see the port 22 open for a new incoming connections
sudo ss -lt

# connect to a SSH server
# ssh <username>@<ip_address>

You can now move files or directories with rsync utility.

# rsync <file/directory> <username>@<ip_address>:<destination>
# for example
rsync my-file.log remote-pit@192.168.0.100:/home/remote-pit/Downloads

gcc

GCC stands for as GNU Compiler Collection. It includes front ends for C, C++, Objective-C, Fortran, Ada, Go, and D, as well as libraries for these languages.

GCC helps you write and execute programs in Linux.

sudo apt install -y gcc

Gnome Tweaks & Shell extensions

GNOME Shell extensions are small pieces of code written by third party developers that modify the way GNOME works.

sudo apt install -y gnome-tweaks chrome-gnome-shell

For Chrome-based browsers install GNOME Shell integration, while for Firefox install Yuri Konotopov’s Add On

The GNOME extensions that I found more useful are:

If you still get an error message like “Although GNOME Shell integration extension is running, native host connector is not detected. Refer documentation for instructions about installing connector.”, install this snap package:

sudo apt install -y gnome-shell-extension-manager

Then, look for Extension Manager application from the menu.

Node Package Manager

NPM is a must-have tool when developing Web applications.

sudo apt install -y npm

# update Node.js to latest release
sudo apt-get remove nodejs
sudo apt install -y curl

# download Node.js v18.x:
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -

# or, download Node.js LTS (Long Term Support)
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -

# install Node.js
sudo apt-get install nodejs

Java

Useful programming language to build cross-platform desktop application.

# Java Development Kit
sudo apt install -y default-jdk

# Java Runtime Environment
sudo apt install -y default-jre

Postman

Postman is an API platform for building and using APIs. It simplifies each step of the API lifecycle and streamlines collaboration, so you can create better APIs faster.

Go to Download page and download the tar.gz file or use the following commands:

sudo apt install -y wget tar
wget https://dl.pstmn.io/download/latest/linux64
tar -xvzf postman-linux-x64.tar.gz
sudo mv Postman /opt/
cd /opt/Postman/
./Postman

ZSH Shell & Oh-My-ZSH

Replace Bourne Shell with a more advanced shell, like ZSH:

sudo apt install -y zsh fonts-powerline fzf

zsh --version # check version
zsh 5.8.1 # (...)
echo $SHELL
/bin/bash

chsh -s $(which zsh)

Logout and login to let the change take effect.

echo $SHELL
/usr/bin/zsh

Install Oh-My-ZSH extension to have better code completions:

sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

Many themes require Powerline Font or Nerd Font. Take a closer look when choosing the shell theme.

Moreover, I suggest you to add the following plugins to .zshrc file:

plugins=(
  git
  emotty
  emoji
  zsh-interactive-cd
  zsh-autosuggestions
  zsh-syntax-highlighting
)

To enable the changes, run:

source ~/.zshrc

Please Note: If you get this error:

[oh-my-zsh] plugin 'zsh-autosuggestions' not found
[oh-my-zsh] plugin 'zsh-syntax-highlighting' not found

Run those commands:

git clone https://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting
source ~/.zshrc

It’s also suggested to set a default bahaviour for oh-my-zsh update policy. I choose to update automatically without asking:

# Uncomment one of the following lines to change the auto-update behavior
# zstyle ':omz:update' mode disabled  # disable automatic updates
zstyle ':omz:update' mode auto      # update automatically without asking
# zstyle ':omz:update' mode reminder  # just remind me to update when it's time

IDEs

IDE stands for Integrated Development Environment. They’re tools that helps you while programming and allow you to be more productive, efficient and effective.

Android Studio

Android Studio is the official IDE for Android application development. From the previous link, download the .tar.gz archive in ~/Downloads directory.

cd ~/Downloads
sudo apt update && sudo apt install -y tar
tar -zxvf android-studio*.tar.gz
# tar -zxvf android-studio-2021.3.1.16-linux.tar.gz # my own command, based on the last AndroidStudio's revision
sudo mv android-studio /opt
cd /opt/android-studio/bin
sudo ./studio.sh

You can optionally add /opt/android-studio/bin to PATH environmental variable. To do so, edit .bashrc file (or another configuration file, based on your shell).

Add the following lines:

PATH="$PATH:/opt/android-studio/bin"
export PATH

At the end of the installation guide, you can also add the desktop entity from the settings icon on the bottom left.

Android Studio desktop entity

You could also install AndroidStudio using JetBrains’ ToolBox or from snap store.

On most Linux machine, you can also configure hardware acceleration for the Android Emulator. Moreover, if you have enough RAM, I strongly suggest to increase heap size to allow a better coding experience.

Arduino IDE 1.x

Go to software section of official Arduino website. Download the version labelled Linux 32 bits (or 64 bits, if your machine supports it).

Open a terminal window:

sudo apt install -y xz-utils # install unzip utility
cd ~/Downloads # navigate to Downloads directory
tar -xvf arduino*.tar.xz # extract the archive contents
rm -rf arduino*.tar.xz # remove the archive
sudo mv arduino* /opt/arduino # move the extracted folder from $HOME/Downloads to /opt/
sudo /opt/arduino/install.sh # complete the installation

Moreover, you need to allow your current user to use the serial communication to communicate with the Arduino boards.

Add yourself to the dialout group:

sudo usermod -a -G dialout $USER

Please Note:

  1. Logout and then log back in for the group changes to take effect (or just sudo restart the machine).
  2. If you accidentally stop the sketch from uploading, you just need to double-click the reset button (reference).

Arduino IDE 2.x

Download the Arduino IDE 2.0 from the official software page.

Then, follow the steps below:

cd ~/Downloads # navigate to Downloads directory

# extract the archive contents to the right sub-directory in /opt/
sudo unzip arduino-ide_2*.zip -d /opt/arduino2

# remove the archive
rm -rf arduino*.zip

# run the IDE (mandatory without sudo)
/opt/arduino2/arduino-ide

# Hit Ctrl + C to stop the execution of the IDE

Depending on your shell type, open the configuration file (.bashrc, .zshrc, …) and add the following alias:

alias arduino2="/opt/arduino2/arduino-ide"

You can now run Arduino IDE 2.x by using the command:

arduino2

Fritzing

Fritzing is an easy-to-use electronic design software. Luckily, there’s an apt package for it:

sudo apt install -y fritzing

JetBrains IDEs

JetBrains is a software house which develop several IDEs. Unfortunately, they’re closed source pieces of software. They’re very similar to one another and are nearly one for each programming language (or framework). The most famous are:

There are some “Community” versions which are available for free. You can use them with a Student Licensee or buy the standard license.

JetBrains also developed Toolbox App. It helps you to easily install, update automatically, update the plugins together with IDE, roll back and downgrade.

To run the Toolbox App, you could need FUSE support.

sudo apt install -y libfuse2

Dowload the latest .tar.gz archive from download link and run those commands:

cd ~/Downloads

# use wget utility only for downloading a package at a specific version
# wget https://download-cdn.jetbrains.com/toolbox/jetbrains-toolbox-1.28.1.15219.tar.gz

# estract the archive
tar -zxvf jetbrains-toolbox*.tar.gz

# delete the archive
rm jetbrains-toolbox*.tar.gz

# move to /opt/ directory
sudo mv jetbrains-toolbox* /opt/jetbrains-toolbox

# run the installer
/opt/jetbrains-toolbox/./jetbrains-toolbox

# the command above perform the two below at the same time
cd /opt/jetbrains-toolbox
./jetbrains-toolbox

MATLAB (abbreviation of “MATrix LABoratory”) is a proprietary multi-paradigm programming language and numeric computing environment developed by MathWorks. MATLAB allows matrix manipulations, plotting of functions and data. It allows algorithms’ implementation, creation of UIs and interfacing with programs written in other languages.

Simulink is a MATLAB-based graphical programming environment for modeling, simulating and analyzing multi-domain dynamical systems.

You need to have a MathWorks account to install MathWorks’ products. Go to Download page and download the .zip Linux installer.

sudo apt install -y unzip

cd ~/Downloads

# create a folder to extract files
mkdir matlab

# unzip the MATLAB file
unzip -qq matlab*.zip -d matlab
cd matlab

# launch installer with sudo permissions
sudo ./install

# if the graphical installer does not starts
xhost +SI:localuser:root && sudo ./install 

Once the graphical installer starts, follow the steps below:

  • Login with MathWorks Account
  • Select the available License
  • Select Matlab Products or Toolbox to install
  • Select the Destination address

The default is:

/usr/local/MATLAB/R2023a/bin

Where R2023a refers to the release year and version (usually a and b).

Please Note: Set as username the actual name of the user logged-in in the computer. You can find you name by launching this command in a Terminal window:

echo $USER

Create MATLAB Symbolic link with:

sudo ln -s /usr/local/MATLAB/R2023a/bin/matlab /usr/local/bin/matlab

Create Matlab Desktop Shortcut Linux with:

nano ~/Desktop/Matlab.desktop

Edit the file as follows:

[Desktop Entry]
Version=1.0
Type=Application
Name=MATLAB
Exec=/usr/local/MATLAB/R2023a/bin/matlab
Icon=/usr/local/MATLAB/R2023a/resources/coreui/matlab/splash.png
Terminal=false

Save the Desktop Shortcut file by pressing Ctr + X and the type Y followed by the Enter Key. Go to the Desktop, right-click on the created file and select the “Allow Launching” option for the desktop entity. You can now launch MATLAB by double-clicking the desktop icon.

Once the installation is complete, remind to clear the Downloads directory:

cd ~/Downloads

rm -rf matlab*.zip matlab

Install new toolboxes after installation

If you try to install new toolboxes using Add-Ons manager, it will throw errors since you have not write access to /usr/local/MATLAB/. If you launch MATLAB as root user, it will throw a License Manager Error -9 Your username does not match the username in the license file.

The correct solution is to set the permission for the current user:

sudo chown -R $USER /usr/local/MATLAB/

Now the user has write access: use the Add-Ons manager carefully! After installing the desired toolboxes, revert the permission change for security reason:

sudo chown -R root /usr/local/MATLAB/

Mbed Studio

Mbed OS is an operative system tailored for IoT devices provides. It provides APIs to develop C++ application, tools, code examples, libraries and drivers for common components.

Mbed Studio is the official IDE for Mbed OS.

cd ~/Downloads
wget https://studio.mbed.com/installers/latest/linux/MbedStudio.sh
chmod +x MbedStudio.sh
./MbedStudio.sh -y -f # -y option accepts all license agreements, -f generates a log of the installation

OpenMV

OpenMV project is about creating low-cost, extensible, Python powered, machine vision modules. It aims to become the Arduino of Machine Vision.

Go to Download page and select the installer based on your operating system and architecture version. It will download a .run file. Open a Terminal and prompt the following commands:

cd ~/Downloads

# rename since long file names are bad to visualize
mv openmv-ide-*.run openmv-ide.run

# give the file execute permission
chmod +x openmv-ide.run

# launch, follow the installer instructions
./openmv-ide.run

# remove the installer
rm openmv-ide.run

Typora

Typora is one of the most powerful Markdown and LaTeX editor I’ve ever seen.

# sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys BA300B7755AFCFAE

wget -qO - https://typora.io/linux/public-key.asc | sudo tee /etc/apt/trusted.gpg.d/typora.asc

# add Typora's repository
sudo add-apt-repository 'deb https://typora.io/linux ./'
sudo apt update

# install typora
sudo apt install -y typora

Take a look at Theme Gallery and don’t forget to activate inline math support to start write LaTeX inside .md files!

Visual Studio Code

For Debian and Ubuntu based distributions, the easiest way to install Visual Studio Code is to download and install the .deb package (64-bit), either through the graphical software center if it’s available, or through the command line with:

sudo apt install -y ./<file>.deb

If you’re on an older Linux distribution, you will need to run this instead:

sudo dpkg -i <file>.deb
sudo apt-get install -f # install dependencies

Note that other binaries are also available on the VS Code download page.

Installing the .deb package will automatically install the apt repository and signing key to enable auto-updating using the system’s package manager. Alternatively, the repository and key can also be installed manually with the following script:

sudo apt install -y wget gpg
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg
sudo install -o root -g root -m 644 packages.microsoft.gpg /etc/apt/trusted.gpg.d/
sudo sh -c 'echo "deb [arch=amd64,arm64,armhf signed-by=/etc/apt/trusted.gpg.d/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" > /etc/apt/sources.list.d/vscode.list'
rm -f packages.microsoft.gpg

Then update the package cache and install the package using:

sudo apt install -y apt-transport-https
sudo apt update
sudo apt install -y code
# sudo apt install -y code-insiders

Conclusion

Documentation

Here is the list of guides and tutorials I used to write this article: