Top 50 Linux Terminal Commands Every Roboticist Should Know

In this tutorial, we will cover the top 50 most popular Linux commands that every roboticist should know.

When you work on robotic projects, you will use the Linux terminal all the time. Learning these essential commands will help you work more efficiently.

Please follow along and try the commands in your own Linux environment. Feel free to pause the video when you need to, and have fun experimenting.

Don’t worry about memorizing these commands. Eventually, you will know these commands by heart after you use them again and again throughout your robotics career.

Prerequisites

Ok, let’s open a terminal window, so we can get started!

If you prefer learning through video rather than text, check out the YouTube video below where I walk you through all the commands, step by step. Otherwise, keep reading.

Identifying current user with “whoami”

The first command we’ll cover is “whoami”. This simple command tells you the username of the currently logged-in user.

whoami
1-whoami

Changing directory with “cd”

The next command we’ll cover is “cd”, which stands for “change directory”. This command allows you to navigate through the filesystem by changing your current working directory.

To use “cd”, type “cd” followed by the path of the directory you want to navigate to, then press Enter. 

For example, to navigate to the “Downloads” directory in your home folder, you would type:

cd Downloads/

If you want to go back to the folder above where you are now, you can use two dots like this:

cd ..

This takes you up one level in your folders.

If you want to go to your ROS 2 workspace, you type:

cd ~/ros2_ws/

The tilde symbol ( ~) is a shortcut that means “my home folder.”

Now let’s move to the Documents folder.

cd ~/Documents/
2-cd

Creating directories with “mkdir”

The “mkdir” command is used to create new directories in the filesystem. It stands for “make directory”.

To create a new directory, type “mkdir” followed by the name you want to give the new directory, then press Enter. 

Let’s try it.

mkdir linux_tutorial

You can also create multiple directories at once by specifying multiple names separated by spaces, like this:

mkdir folder1 folder2 folder3
3-mkdir

Removing directories with “rm -rf”

The “rm -rf” command is used to delete directories.

To remove a directory, type “rm -rf” followed by the name of the directory you want to remove.

For example, 

rm -rf folder3
4-rm-rf

Creating empty files with “touch”

The “touch” command is used to create empty files in the filesystem. It can also be used to update the timestamp of existing files without modifying their contents.

To create a new empty file, type “touch” followed by the name you want to give the file, including the desired extension, then press Enter. 

For example, to create an empty text file named “new_file.txt”, you would type:

cd linux_tutorial
touch new_file.txt

You can create multiple empty files at once by specifying multiple names separated by spaces, like this:

touch file1.txt file2.txt file3.txt

Editing text files using “nano” and “gedit”

When working with text files in Linux, you can use command-line text editors like “nano” or graphical text editors like “gedit”.

To open a file with “nano”, type “nano” followed by the filename, then press Enter. 

For example, to open a file named “example.txt”, you would type:

nano example1.txt

If the file doesn’t exist, “nano” will create a new empty file with that name. You can then type your text, and use keyboard shortcuts like Ctrl+O to save and Ctrl+X to exit.

To open a file with “gedit”, type “gedit” followed by the filename, then press Enter. 

Install gedit:

sudo apt-get install gedit

Create the file:

gedit example2.txt

“gedit” provides a graphical user interface with menu options for saving and closing files.

Listing directory contents with “ls” and “dir”

The “ls” command is used to list the contents of a directory. It stands for “list”.

To list the files and directories in your current location, simply type “ls” and press Enter. This will display a plain listing of the names.

ls

The “dir” command is similar to “ls” but provides a slightly different output format.

dir
5-ls-dir

Creating a bash script

Bash scripts are files containing a series of commands that can be executed together.

To create a bash script, start by opening a new file in a text editor (like nano or gedit). Begin the script with the shebang line “#!/bin/bash” to indicate that it should be run with the bash shell.

Then, write your commands one per line. For example:

gedit basic_bash_script_example.sh

Write this code:

#!/bin/bash 
echo "Hello, world!" 
ls -l
6-bash-script

Save the file, and close gedit.

So that we can run the script, we need to make it executable using the “chmod” command with the “+x” option:

chmod +x basic_bash_script_example.sh

You can then run your script:

bash basic_bash_script_example.sh

You can also type:

./basic_bash_script_example.sh
7-basic-bash-script

Changing file permissions with “chmod”

The “chmod” command is used to change the permissions of files and directories. It stands for “change mode”.

Permissions specify who can read, write, and execute a file. They are represented by a combination of letters (r for read, w for write, x for execute) for each of the three user classes (owner, group, others).

To see the permissions, create a file now:

touch chmod_example.txt

Now type:

ls -la

To change permissions, use “chmod” followed by the desired permission settings and the filename. For example, to give everyone read, write, and execute permissions (r, w, and x, respectively), you type:

chmod 777 chmod_example.txt

Exploring the .bashrc file

The .bashrc file is a script that is executed whenever you open a new terminal window. It is located in your home directory and is used to set up your environment, define aliases, and set environment variables.

To edit your .bashrc file, you can use any text editor. For example:

gedit ~/.bashrc

Creating command aliases with “alias”

An alias is a shortcut that you can use to run a command or a series of commands. You can define aliases in your .bashrc file so that they are available every time you open a new terminal window.

To create an alias, you use the alias command followed by the name of the alias and the command(s) you want it to run.

Let’s say you want to create a quick command to build a ros2 workspace.

gedit ~/.bashrc

Write this at the bottom of the .bashrc file:

alias build='cd ~/ros2_ws/ && colcon build && source ~/.bashrc'

Save the file, and close it.

Now, whenever you want to build your ROS 2 workspace, you can type:

build
9-alias

Setting environment variables using export

Environment variables are variables that are available to all the processes running in a terminal window.

You can set environment variables in your .bashrc file so they are available every time you start a new terminal window.

To set an environment variable, use the export command followed by the name of the variable and its value.

For example, to set an environment variable called MY_VAR to the value 8, you can add the following line to your .bashrc file:

gedit ~/.bashrc

Add this at the bottom of the file.

export MY_VAR=8

Save the file, and close it.

Open a new terminal window, and verify the value of MY_VAR.

echo $MY_VAR
10-echo-my-var

Clearing terminal screen with “clear”

The “clear” command is used to clear the terminal screen, moving the prompt to the top of the screen.

Simply type “clear” and press Enter to clear the screen:

clear

This command is useful when your terminal gets cluttered with output and you want to start with a clean screen.

Exploring options with “intro to options”

Most Linux commands have options that modify their behavior. Options are specified using a dash (“-“) or double dash (“–“) followed by a letter or word.

For example, to see the help information for the “ls” command, you can use:

ls --help

Alternatively, the see the command’s manual, you can type:

man ls

Then press “q” to quit.

Determining present working directory with “pwd”

The “pwd” command is used to print the current working directory (the directory you are currently in).

To use this command, simply type “pwd” and press Enter:

pwd
11-pwd

Removing files with “rm”

The “rm” command is used to remove files.

To remove a file, type “rm” followed by the name of the file you want to remove. For example, to remove a file called “chmod_example.txt”:

cd ~/Documents/linux_tutorial/
rm chmod_example.txt

To remove a folder, add -rf (recursive + force) to the command:

clear
12-rm
dir
mkdir remove_test
dir
rm -rf remove_test
dir

Opening files or directories with “open”

The “open” command is used to open files or directories with the default application associated with that file type.

To open a file or directory, type “open” followed by the name or path of the file or directory you want to open. For example:

open ~/ros2_ws/
13-open

Moving files or directories with “mv”

The “mv” command is used to move files and directories from one location to another. It can also be used to rename files and directories.

To move a file, type “mv” followed by the name of the file you want to move and the destination directory. 

For example, to move a file called “new_file.txt” to the “Downloads” directory:

cd ~/Documents/linux_tutorial
dir
mv new_file.txt ~/Downloads/
dir

Open a new terminal to check:

cd ~/Downloads/
dir

To rename a file, type “mv” followed by the current filename and the new filename. For example, to rename “old_name.txt” to “new_name.txt”:

cd ~/Documents/linux_tutorial
touch old_name.txt
dir
mv old_name.txt new_name.txt
dir
14-mv

Copying files or directories with “cp”

The “cp” command is used to copy files and directories from one location to another.

To copy a file, type “cp” followed by the name of the file you want to copy and the destination directory. 

For example, to copy a file called “copy_example.txt” to the “Downloads” directory:

touch copy_example.txt
cp copy_example.txt ~/Downloads

Open a new terminal to check:

open ~/Downloads/

To copy a directory and its contents, use the “-r” (recursive) option:

mkdir my_cp_directory
cp -r  my_cp_directory ~/Downloads/
15-cp

Previewing beginning of files with “head”

The “head” command is used to display the first few lines of a file.

To preview the beginning of a file, type “head” followed by the name of the file. 

For example, to display the first 10 lines of a file called “head_example.txt”:

gedit head_example.txt

Type this inside the file:

# This is
# Automatic Addison
# Keep building!
# 4
# 5
# 6
# 7
# 8
# 9
# 10
# 11
# 12
# 13
# 14
# 15

Save the file, and close it.

head head_example.txt

To display the first 5 lines:

head -n 5 head_example.txt
16-head

Viewing end of files with “tail”

The “tail” command is used to display the last few lines of a file.

tail head_example.txt

Similar to “head”, you can change the number of lines displayed using the “-n” option. For example, to display the last 5 lines:

tail -n 5 head_example.txt
17-tail

Displaying current date and time with “date”

The “date” command is used to display the current date and time.

date

The output will show the current date and time in the default format.

You can customize the output format using format specifiers. For example, to display the date in the format “YYYY-MM-DD”, use:

date +"%Y-%m-%d"

Refer to the “date” command’s manual page (“man date”) for more information on available format specifiers.

man date
18-date

Redirecting standard output with “redirecting standard output”

In Linux, you can redirect the output of a command to a file instead of displaying it in the terminal. This is done using the “>” operator.

To redirect the output of a command to a file, type the command followed by “>” and the name of the file. For example, to redirect the output of the “ls” command to a file called “directory_contents.txt”:

cd ~/Documents/linux_tutorial
ls > directory_contents.txt

If the file doesn’t exist, it will be created. If the file already exists, its contents will be overwritten.

To append the output to an existing file instead of overwriting it, use the “>>” operator:

ls >> directory_contents.txt

Concatenating and displaying files with “cat”

The “cat” command is used to concatenate and display the contents of files.

To display the contents of a single file, type “cat” followed by the name of the file. 

cat directory_contents.txt
19-cat

Viewing text files with “less”

The “less” command allows you to view the contents of a text file one page at a time. “less” is particularly useful for viewing large files that don’t fit on a single screen.

less head_example.txt

Once you’re in “less”, you can navigate through the file using various keyboard shortcuts:

  • Press “Space” to go to the next page
  • Press “b” to go back one page
  • Press “q” to quit “less” and return to the terminal

Displaying text with echo

The “echo” command is used to display text or the value of variables in the terminal.

To display a simple message, type “echo” followed by the text you want to display. 

For example:

echo "I am Automatic Addison"

You can also use “echo” to display the value of environment variables. 

For example, to display the value of the “ROS_DISTRO” variable:

echo $ROS_DISTRO
20-echo

Counting words, lines, and characters with “wc”

The “wc” command is used to count the number of words, lines, and characters in a file.

wc head_example.txt

The output shows the number of lines, words, and characters in the file, in that order.

21-wc

Connecting commands with piping

In Linux, you can connect multiple commands together using pipes. The output of one command becomes the input of the next command.

To use pipes, type the first command followed by the pipe symbol (“|”), then type the next command. 

For example, to count the number of files in a directory:

ls | wc -l

In this example, the output of the “ls” command (the list of files) is piped to the “wc” command, which counts the number of lines (“-l” option).

You should see this as your output:

9

Sorting lines of text with “sort”

The “sort” command is used to sort lines of text alphabetically or numerically.

To sort the contents of a file, type “sort” followed by the name of the file. 

For example, to sort the lines in a file called “head_example.txt”:

sort head_example.txt

The output will show the sorted lines of the file.

You can also sort in reverse order.

sort -r head_example.txt

Note that this sort command will not change the actual file. It will just display the sorted output in the terminal window.

22-sort

Performing shell expansions

Shell expansions are a feature that modify the way the shell interprets and executes commands. 

Suppose you need to quickly create directories for three different projects each named for the current year:

mkdir -p Project_{A,B,C}_$(date +%Y)

This command creates directories named Project_A_2024, Project_B_2024, and Project_C_2024 in the current directory.

dir

{A,B,C} expands to create three strings: A, B, and C.

$(date +%Y) executes the date command to fetch the current year (e.g., 2024), replacing it in the command.

23-shell-expansion

Comparing files line by line with “diff”

When working on projects that involve multiple versions of files, especially in a collaborative environment, it’s essential to track and understand changes between different file versions. The diff allows you to compare two files line by line and outputs the differences between them.

Let’s create a copy of this file:

cp head_example.txt head_example_copy.txt
gedit head_example_copy.txt

Modify one of the lines in the file, and save it.

I will remove the first line “This is”.

24-diff-a

Save the file, and close it.

To use diff, simply provide the names of the two files you want to compare:

diff head_example.txt head_example_copy.txt

This command will display the lines that differ between the two files, along with symbols that indicate whether lines were added, deleted, or changed. 

25-diff-b

Lines prefixed with < indicate content present in the first file but not in the second.

Lines prefixed with > show content that is in the second file but not in the first.

Let’s take a closer look at our output.

“1d0” means:

  • The line 1 from the first file (head_example.txt)
  • Is deleted (d)
  • When compared to the very beginning (before line 1) of the second file (head_example_copy.txt)

< # This is: 

  • This line shows the content that exists in the first file but not in the second file. The < symbol indicates that this line is from the first file.

Searching for files with “find”

The “find” command is used to search for files and directories based on various criteria such as name, size, or modification time.

To search for a file by name, type “find” followed by the directory to search in and the “-iname” option with the file name pattern. 

For example, to search for a file named “head_example_copy.txt” in the Documents directory and its subdirectories:

cd ~/Documents/
find . -iname "head_example_copy.txt"

To find a folder named “folder1” in the current directory or its subdirectories, you can use the find command with a slight modification. Here’s the command you can use:

find . -type d -iname "folder1"
26-find

Searching text with “grep”

The “grep” command is used to search for specific text patterns within files.

To search for a text pattern in a file, type “grep” followed by the pattern and the file name. 

For example, to search for the word “example” in a file named “grep_example.txt”:

cd ~/Documents/linux_tutorial/
echo "This is an example line." > grep_example.txt
cat grep_example.txt
echo "Another line here." >> grep_example.txt
cat grep_example.txt
echo "One more example." >> grep_example.txt
cat grep_example.txt

Now type:

grep "example" grep_example.txt

You can even make the search case-insensitive:

grep -i "EXAMPLE" grep_example.txt

The output will show the lines in the file that contain the search word.

27-grep

Estimating file space usage with “du”

The “du” command is used to estimate the disk space used by files and directories.

To display the disk space used by a specific file or directory, type “du” followed by the file or directory name. 

For example:

du -h ~/ros2_ws/

The output will show the disk space used by each file and subdirectory within “my_directory”, as well as the total disk space used by the directory.

28-du

Displaying filesystem space usage with “df”

The “df” command is used to display information about the disk space usage of filesystems.

To display the disk space usage of all mounted filesystems, simply type “df”:

df -h
29-df-h

Viewing command history with “history”

The “history” command is used to display a list of previously executed commands in the current shell session.

To view the command history, type “history”:

history
30-history

Displaying process status with “ps”

The “ps” command is used to display information about running processes.

To display the processes associated with the current shell session, type “ps”:

ps

The output will show the process ID (PID), terminal, CPU time, and command name for each process.

To display all processes running on the system, use the “-e” option:

ps -e
31-ps

Displaying system resource usage with “top”

The “top” command is used to display real-time information about system resource usage and running processes.

To start “top”, simply type “top”:

top

Press “q” to quit “top”

Press “M” to sort processes by memory usage (i.e. Shift + M)

Press “P” to sort processes by CPU usage (i.e. Shift + P)

32-top

Terminating processes with “kill” and “killall” 

The “kill” command is used to send a signal to a process, typically to terminate it, while the “killall” command is used to send a signal to all processes with a specified name.

To terminate a process with “kill”, type “kill” followed by the process ID (PID). For example, to terminate a process with PID 1234:

kill 1234

To terminate all processes with a specific name using “killall”, type “killall” followed by the process name. For example, to terminate all processes named “firefox”:

Start firefox.

firefox

Check out the processes:

top

Close firefox.

killall firefox

Display background processes with “jobs”

The “jobs” command is used to display a list of background processes started by the current shell session, while the “bg” and “fg” commands are used to manage these processes.

To start a process in the background, append an ampersand (“&”) to the end of the command. 

For example, let’s start the sleep command as a background process:

<command> &

Becomes:

sleep 100 &

To list the background processes, type “jobs”:

jobs

Each process will be displayed with a job number and its status (e.g., “Running” or “Stopped”).

33-jobs

Managing background processes with “bg,” and “fg”

To bring a background process to the foreground, type “fg” followed by the job number. 

For example, to bring job 1 to the foreground:

fg %1

To send a foreground process to the background, press “Ctrl+Z” to suspend it, then type “bg” to resume it in the background:

bg
34-bg-fg

Compressing files with “gzip”

The “gzip” command is used to compress files to reduce their size.

To compress a file, type “gzip” followed by the file name. 

For example, to compress a file named “grep_example.txt”:

cd ~/Documents/linux_tutorial
touch grep_example.txt
gzip -k grep_example.txt
dir

The compressed file will have the extension “.gz” added to its name, e.g., “grep_example.txt.gz”.

dir
35-gzip

Decompressing files with “gunzip”

The “gunzip” command is used to decompress files that were compressed with “gzip”.

To decompress a file, type “gunzip” followed by the file name. 

For example, to decompress a file named “grep_example.txt.gz”:

gunzip -k grep_example.txt.gz

The decompressed file will have the “.gz” extension removed from its name.

36-gunzip

Archiving and extracting files with “tar”

The “tar” command is used to create and extract archive files, which are collections of multiple files and directories combined into a single file.

For example, to create an archive named “archive.tar” containing the files “file1.txt” and “file2.txt”:

touch tar_example_file1.txt tar_example_file2.txt
tar cf archive.tar tar_example_file1.txt tar_example_file2.txt
dir
37-tar

Now remove the files:

rm tar_example_file1.txt tar_example_file2.txt 

To extract the contents of a tar archive, type “tar” followed by the “xf” options and the archive file name. 

For example, to extract the contents of an archive named “archive.tar”:

tar xf archive.tar

The files and directories will be extracted into the current directory.

Building and executing commands with “xargs”

The “xargs” command is used to build and execute commands from standard input.

A common use case for “xargs” is to pass the output of one command as arguments to another command. 

Let’s create a test environment for this command:

mkdir xargs_test && cd xargs_test
touch file1.txt file2.txt file3.txt

Use xargs to list file contents:

echo file1.txt file2.txt file3.txt | xargs cat

Add content to files:

echo "Hello" > file1.txt
echo "World" > file2.txt
echo "Xargs" > file3.txt

Run the command again:

echo file1.txt file2.txt file3.txt | xargs cat
38-xargs

This basic demonstrates how xargs takes input from one command and uses it as arguments for another. 

Now let’s go back to the previous directory.

cd ..

Creating symbolic links with “ln”

The “ln” command is used to create links between files. There are two types of links: hard links and symbolic (soft) links.

To create a symbolic link, type “ln” with the “-s” option, followed by the source file and the link name. 

For example:

touch symbolic_link_example.txt
ln -s symbolic_link_example.txt my_test_link

The symbolic link “my_test_link” will point to “symbolic_link_example.txt”. 

When you access “my_test_link”, it will redirect you to the contents of “symbolic_link_example.txt”.

Symbolic links can point to files or directories on different filesystems, and they will continue to work even if the source file is moved or deleted.

Now let’s test this symbolic link by adding some text to the original file:

echo "Hello, World!" > symbolic_link_example.txt
cat my_test_link
39-symbolic-link

Replacing Words with “sed”

The “sed” command is used to modify text in a file or input stream. You can use “sed” to replace occurrences of a word or phrase with another:

cd ~/Documents/linux_tutorial
echo "The old_word is here. Another old_word is there." > test.txt
cat test.txt
sed -i 's/old_word/new_word/g' test.txt
cat test.txt
40-sed

Executing commands with superuser privileges with “sudo”

The “sudo” command is used to execute commands with superuser (root) privileges.

To execute a command with superuser privileges, type “sudo” followed by the command. 

For example, to update the package list on an Ubuntu system:

sudo apt-get update

You will be prompted to enter your user password. Once authenticated, the command will run with superuser privileges.

The “sudo” command grants temporary superuser privileges for a single command, without the need to switch to the root account.

Changing user password with “passwd”

The “passwd” command is used to change a user’s password.

To change your own password, simply type “passwd”:

passwd

You will be prompted to enter your current password, then prompted to enter and confirm the new password.

Modifying file ownership with “chown”

To demonstrate the use of chown, let’s create a test file:

cd ~/Documents/linux_tutorial
touch chown_example.txt

To see the current owner of the file, use the ls command with the -l option:

ls -l chown_example.txt

To change the owner of a file, use “chown” followed by the new owner and the file name. 

For example, to change the owner of “chown_example.txt” to root:

sudo chown root chown_example.txt

You’ll be prompted for your password. After entering it, check the new ownership:

ls -l chown_example.txt
41-chown

We’ve learned many important Linux commands for robotics in this tutorial.

I hope this guide helps you feel more confident using Linux, and remember, all great roboticists started as beginners too – so keep practicing, stay curious, and enjoy your robotics journey.

Keep building!

How to Install and Configure Visual Studio Code for ROS 2

In this tutorial, we will go over how to install and configure Visual Studio Code for your ROS 2 projects.

Visual Studio Code, often shortened to VS Code, is a free and open-source code editor developed by Microsoft. It’s a popular choice for programmers of all levels, from beginners to professionals, because it’s:

  • Lightweight and fast: It doesn’t take up much space on your computer and starts up quickly, so you can get coding right away.
  • Versatile: It supports a wide range of programming languages, including JavaScript, Python, Java, C++, and more. You can also install extensions to add support for even more languages.
  • Customizable: You can personalize VS Code with themes, extensions, and keyboard shortcuts to make it work the way you want.
  • Feature-rich: It comes with built-in features like syntax highlighting, code completion, and debugging, which can help you write better code faster.

Let’s get started!

Prerequisites

Directions

If you prefer learning through video rather than text, check out the YouTube video below where I walk you through the entire process step by step. Otherwise, keep reading.

Go to the download page at Visual Studio Code.

Click the .deb button.

1-click-deb
2-download

Open a terminal window, and type:

cd ~/Downloads

Check the name of the file:

dir
3-check-name-of-file

Run the following command, replacing “filename.deb” with the actual name of your file:

sudo dpkg -i filename.deb

Enter your password when prompted.

Click Yes if you see this screen.

4-click-yes-if-you-see-this-code

The installation will start. Wait for it to complete.

Now, navigate to your workspace.

cd ~/ros2_ws/

Open VS Code by typing this command in a terminal window:

code .

Click the checkbox next to “Trust the authors of all files in the parent folder ‘ubuntu’”.

5-open-vs-code

Click “Yes, I trust the authors” to continue.

Choose your desired color theme by clicking the “Browse Color Themes” button. You can also go to the File > Preferences > Theme > Color Theme menu item.

6-choose-color-theme

I will select Solarized Dark because it reduces blue light emission from my screen, which can help minimize disruption to my natural sleep-wake cycle. This theme is particularly beneficial for low-light environments and late-night coding sessions, as it reduces eye strain and makes extended work more comfortable.

A similar option if you prefer lighter themes is Solarized Light.

Now you need to scroll down on the top menu, and select “Mark Done”.

7-select-mark-done

Double-click on the Extensions button on the left side of the window.

8-extensions-button

Search for the “C/C++” extension by Microsoft.

9-cpp-by-microsoft

Install it by clicking the Install button.

Search for the “ROS” extension.

Install the ROS extension from Microsoft by clicking the Install button. 

10-ros-extension-by-microsoft

Now let’s install the CMake extension. Search for “CMake”, and install the version made by twxs.

11-twxs

Install the CMake Tools extensions. Search for “CMake Tools”, and install the version made by Microsoft.

12-cmake-tools

Install the XML extensions. Search for “XML”, and install the version made by Red Hat.

13-xml-extension

Now let’s install the Python extension. Search for “python”, and install the version made by Microsoft. Note: You may have already installed it. 

14-python-extension

Install the autoDocstring extension. Search for “autoDocstring”, and install the version made by Nils Werner.

15-autodoctring

Let’s set our default indentation to 2 spaces.

Using the menu: Go to File > Preferences > Settings

Search for “Indentation” in the settings panel.

Change the following values:

“Editor: Tab Size”: Set this to 2 to control the width of a tab character.

16-set-to-2-indentation

“Editor: Insert Spaces”: Set this to true to ensure that pressing Tab inserts spaces instead of a literal tab character.

17-insert-spaces-to-true

The changes should take effect immediately. 

Now you can close VS Code by going to File -> Close Window.

You can reopen VS code inside your workspace like this:

cd ~/ros2_ws/src
code .

That’s it! I’ll see you in the next tutorial. Keep building!

How to Install Ubuntu 24.04 Virtual Machine on a Windows PC

In this tutorial, you will install Ubuntu and Virtual Box on your personal computer. Whether you have a computer using Windows or a Mac, by the end of this tutorial, you will have Ubuntu all setup and ready to go.

If you prefer learning through video rather than text, check out the YouTube video below where I walk you through the entire process step by step. Otherwise, keep reading.

What is Ubuntu?

Ubuntu is an operating system for your computer, just like Windows or macOS, but it is based on Linux –  a free, open-source system that serves as the foundation for many computer programs. 

Ubuntu provides a user-friendly desktop environment see in the lead image for this blog post. 

Why use Ubuntu to program robots when we could use Windows or macOS?

Three reasons:

  1. It is free to use.
  2. It is open source, which means the code is publicly available for you to modify and distribute without paying thousands of dollars in license fees.
  3. It is fully supported by ROS 2, the most popular framework in the world for writing robotics software.

What is VirtualBox?

VirtualBox is a program that lets you run a different operating system inside your current one. It is like having a computer within your computer. 

VirtualBox creates a safe, isolated space where you can experiment with other operating system environments without changing anything on your main Mac or Windows-based computer.

What About a Real-World Robotics Project?

On a real-world robotics project, you will use a small computer instead of your desktop PC. Examples include the Intel NUC, Raspberry Pi, or NVIDIA Jetson boards. 

These small computers serve as your robot’s “brain,” taking care of all the decisions on what actions the robot should take based on data from sensors like cameras, LIDAR, wheel encoders, and GPS. 

We’ll be harnessing the power of Ubuntu on a desktop computer, creating a robust virtual environment for our robotics journey. This setup is not just a convenient starting point for beginners—it is actually the ideal platform for any robotics project, regardless of experience level. 

Why Simulation Matters in Professional Robotics

It is worth mentioning that even in professional robotics jobs, a significant amount of work is done in simulation environments similar to what we’re setting up. There are three reasons for this: Speed, Spend, and Safety. I call it the three S’s:

  1. Speed: You can rapidly prototype new ideas in a simulated environment before committing to physical builds.
  2. Spend: Developing and testing in a virtual environment is much cheaper than building and testing physical prototypes for every iteration.
  3. Safety: You can test potentially dangerous scenarios without damaging expensive hardware or running into people:
    1. An example would be testing a cliff sensor for a mobile robot that is designed to keep the robot from falling down stairs. 
    2. You wouldn’t want to test that logic on a real robot without doing it in simulation first!

By starting with this virtual Ubuntu setup, you’re not only learning the basics but also preparing yourself for practices used in real-world robotics development. This approach bridges the gap between beginner-friendly learning and professional-grade tools and methodologies.

Download the Ubuntu Image

Now let’s download Ubuntu. 

First, go to the Ubuntu Releases page (https://releases.ubuntu.com/) on the Ubuntu website to find the latest version of Ubuntu that has long term support (LTS). 

As of the date of this writing, the latest version is Ubuntu 24.04 LTS (Noble Numbat).

Click on “Ubuntu 24.04 LTS (Noble Numbat)”.

1-ubuntu-releases-2024

Click on the 64-bit PC (AMD64) desktop image.

2-64-bit-pc-desktop-image

This .iso file is large. It will take a while to download. Just go do something else and come back to it when it is finished.

When the download finishes, you can either keep the file in the default download location, which for me is my Desktop. Or, you can move the file to another directory on your computer.

Now, go to the next step.

Install VirtualBox

Let’s install VirtualBox. 

Go to the VirtualBox downloads page. Here is the link.

Select the version that is compatible with your computer. I will click “Windows hosts” since I am using a Windows-based computer.

3-download-virtual-box

Click on the executable file that you just downloaded. 

Follow the prompts to install it on your machine. 

Accept all the defaults by clicking either Next, Yes, Install, or Finish through all the prompts.

You can find detailed installation instructions for all operating systems (Windows, Mac OS, and Linux) in the instruction manual if you encounter problems.

When you are finished downloading and installing VirtualBox, you can delete the original executable file that you used to install the program. You don’t need it anymore.

Create a Virtual Machine

Now that VirtualBox is installed, we need to create a new virtual machine using the Ubuntu image we downloaded earlier.

Open Virtual Box.

Click the New button in the toolbar.

4-click-new-button

Name and Operating System

First, let’s complete the “Name and Operating System” section.

On the “Name” line, type in a descriptive name for your operating system. I will call mine “Ubuntu24.04”.

5-name-and-operating-system

On the “Folder” line, you can keep the default Folder path. This folder is where your virtual machines will be stored. 

On the “ISO Image” line, select the path to the Ubuntu .iso file you downloaded earlier.

On the “Type” line, select Linux.

On the “Subtype” line, select Ubuntu.

On the “Version” line, select Ubuntu (64-bit).

Select “Skip Unattended Installation”. By selecting this option, we will manually go through the entire installation process of the operating system. 

Hardware

Click on the arrow next to “Hardware” to expand the menu options.

6b-hardware-options

On the “Base Memory” line, move the slider to 16384 MB (megabytes). This memory size will be enough for us to run our robotics simulator, Gazebo, which requires a lot of memory.

On the “Processors” line, select 8 CPUs. If your computer supports it, you can set a higher number. I like to make sure my slider stays within the safe, green color to avoid problems.

Click on the arrow next to “Hard Disk” to expand the menu options.

6-50gb-storage

Click on the slider bar to set 50.00 GB for the storage space.

Click “Finish”.

Highlight Ubuntu24.04, and click Settings.

6c-settings

Click Display.

6d-display

Change Video Memory to 128 MB (megabytes).

Click OK.

Install Ubuntu

Highlight Ubuntu24.04, and click Start on the top menu.

7-doubleclick-start

A startup window will appear.

Select “Try or Install Ubuntu” by Pressing Enter.

8-startup-window

Choose your language. I will select “English”.

9-choose-language

Click Next.

On the “Accessibility in Ubuntu” panel, click Next.

10-accessibility-in-ubuntu

On the “Keyboard layout” panel, select your desired keyboard layout, and click Next.

11-select-keyboard-layout

On the “Connect to the internet” panel, select “Use wired connection”, and click Next.

12-connect-to-the-internet

If you get prompted to update the Ubuntu installer, do that now.

Then click the “Install Ubuntu 24.04.1 LTS” icon on the Ubuntu desktop to continue the installation.

On the “What do you want to do with Ubuntu?” panel, select “Install Ubuntu”, and then click Next.

13-install-ubuntu

On the “How would you like to install Ubuntu?” panel, select “Interactive installation”, and then click Next.

14-interactive-installation

On the “What apps would you like to install to start with?” panel, select the “Default selection”, and then click Next.

15-what-apps-start-with

On the “Install recommended proprietary software?” panel, select both checkboxes, and then click Next.

16-install-recommended

On the “How do you want to install Ubuntu?” panel, select “Erase disk and install Ubuntu”.

17-how-want-install-ubuntu

Click Next.

On the “Create your account” panel, fill in your information with your desired name (e.g. “ubuntu”). Also fill in your password.

18-create-your-account

Deselect “Require my password to log in”.

Click Next.

Select your time zone, and then click Next.

19-select-your-timezone

On the “Review your choices” panel, click Install.

20-review-your-choices

Sit back and relax while Ubuntu installs.

21-after-click-install

Click “Restart now” when the installation finishes.

22-restart-when-done

When you see a message that says “Please remove the installation medium, then press Enter”, press Enter on your keyboard.

22b-remove-installation-medium

Configure Ubuntu

You will now see a welcome screen.

23-welcome-screen

Click Next.

On the “Enable Ubuntu Pro” panel, select “Skip for now”, and click Next.

I will select “No, don’t share system data”, and click Next.

24-help-improve-ubuntu

On the “Get started with more applications” panel, click Finish.

25-click-finish

On the bottom left side of the screen, click the ring icon.

26-click-icon

Right-click the terminal icon, and click “Pin to Dash”.

27-pin-to-dash

Click the ring icon again to return to the Desktop.

Now let’s make sure your user has sudo privileges. Sudo privileges allow a user to execute commands with superuser (administrative) rights, enabling them to perform tasks that require higher levels of access on the system. 

Click the terminal icon on the left side of the screen.

30-terminal-icon

Type the following command inside the terminal window, and press Enter.

whoami

This is your username. 

Now type:

sudo adduser <username> sudo

Replace <username> with your username.

31b-add-sudo-user

Now shutdown the virtual machine by typing the following command and pressing Enter on the keyboard.

sudo shutdown -h now

Install VirtualBox Guest Additions

Now we need to install VirtualBox Guest Additions. 

VirtualBox Guest Additions are a set of applications that improve the performance and usability of virtual machines.

Highlight Ubuntu24.04, and click Start on the top menu to launch the Desktop environment.

Open a terminal window, and type the following commands to upgrade the operating system software packages:

sudo apt-get update -y

When prompted for the password, type in your password and press Enter.

sudo apt-get upgrade -y

Clear out all the logs in the terminal by typing the following command, and pressing Enter:

clear

Now reboot the machine.

reboot

When you get back to the Desktop, open a terminal window, and type the following command.

sudo apt install build-essential dkms linux-headers-$(uname -r) -y

Next, go to the menu bar at the top of the Virtual Machine.

Click “Devices”.

32-menu-bar-click-devices

Click “Insert Guest Additions CD image” to mount the Guest Additions ISO file inside your virtual machine.

Click the Files icon on the left side of the screen.

32-click-files-icon

Click VBox_GAs on the left panel.

33-vbox-gas

Right click on autorun.sh and select “Run as program”. (you can also click Run Software at the top)

34-run-as-program
34-run-software

Enter your password when the Authentication Required pop-up window appears.

Click “Authenticate.”

Once all the logs stop, press Enter to close the installation window.

34b-logs-stop

Shutdown your system with the following command inside a terminal window:

sudo shutdown -h now

Highlight Ubuntu24.04 on the left panel.

Click Machine -> Settings in the dropdown menu at the top of Virtual Box.

Go to General -> Advanced on the Settings menu.

Enable “Bidirectional” for both “Shared Clipboard” and “Drag’n’Drop”.

35-enable-bidirectional

Click OK.

Highlight Ubuntu24.04 on the left panel.

Click Start to launch the Desktop environment again.

If the environment doesn’t launch after a minute or so, click File -> Close, and power everything down, and try launching it again by pressing the Start button on the home menu.

Change the Screen Resolution

You may notice some annoying flickering that happens on your screen. This flickering happens either at random times or when I try to move windows with the virtual machine. The issue is due to the screen resolution.

Do the following steps to make this go away:

Go to the View menu at the top of the window.

36-view-autoresize

To set a specific fixed resolution, go to View -> Virtual Screen 1, and select your desired resolution (e.g. 1920 x 1080).

Congratulations, you have finished installing and setting up Ubuntu. 

I will see you in the next tutorial!