Comment on page
Prerequisite handbook for GAAS: Linux tutorial
Here are the prerequisite knowledges of using Linux operating system, this handbook only includes the skills used in the tutorial of GAAS
It's necessary to be able to use the Linux shell proficiently since the PX4 and ROS are based on Linux operating system. Here is the terminal interface of the Linux shell:
Linux terminal window
Similar as Windows, the file system of Linux is organized as a directory tree, a typical structure of Linux file system is shown as follows:
/is the entry point of the Linux file system，there will be many other files and folders under
With the authority of the Linux file system, by defalut every user can only own the full access of their own Home folder, the path of a user's Home folder is
For example, the Home folder path of the user
/home/gi, it can be replaced with
~, which means
/home/gi/GAAScan be replaced with
./represents the current directory. If you would like to execute a binary file in the current folder, the path should start with
./. For example, there is a binary file
helloin the current folder, it will be executed with the following command:
../represents the parent folder.
Here is a list of useful commands:
manshows the user manual，you can use
man commandto show the manual of a command
lslists the contents of your current working directory, use
ls -lto show them as a list;
cdchanges the current working directory to another directory, use
cd ..to change to the parent directory;
mkdirmakes a directory;
cpcopys a file or a folder , usage is
cp source target, to copy a directory you need the parameter
mvmoves a file or a folder , the usage is similar with
cp, but you needn't use
-rto move a directory;
catshows the content of a text file;
clearcleans up the contents in current terminal;
touchcreates a new blank text file;
You can press Ctrl+C to stop a running process.
For more information about the Linux shell, you can visit this site:
ls -lto see the details of files in a list：
At the directory of
ls -lyou can find that most of the files are owned by the system (owner is
root)，modifying these files will be rejected with
permission denied. If the current user owns the
rootprivilege, you can use
sudoto launch a command with
rootprivilege. For example, to make a blank file in
/with the name
text.txt, you can use
sudo touch text.txt
A password will be required, notice that the characters you input will not be displayed:
Here is a list of useful commands:（Remember to use
chownchanges the owner of a file or folder, you can use it with
sudoto change a file's owner from
rootto the current user.
chmodchanges the permission of a file, use
chmod +xto add the permission of executable to a file (e.g. a shell script).
1、Introduction to the variables：
Variables are a way of passing information from the shell to programs when you run them. Programs look "in the environment" for particular variables and if they are found will use the values stored. Some are set by the system, others by you, yet others by the shell, or any program that loads another program.
Standard UNIX variables are split into two categories, environment variables and shell variables. In broad terms, shell variables apply only to the current instance of the shell and are used to set short-term working conditions; environment variables have a farther reaching significance, and those set at login are valid for the duration of the session.
For example, the command
lsis actually a executable binary file located in the
/bindirectory——use the command
whichto find the actual path of a command:
Note: please check the variable first if an error like "xxx not found" occurs, here "xxx" is a component that has already been installed on your system.
Each time you login to a UNIX host, the system looks in your home directory for initialisation files. Information in these files is used to set up your working environment. The Ubuntu is using the bash shell, and the bash shell uses the script of
bashrc. This script is located in the home folder and its a hidden file (filename starts with
.), with the actual path
You can add new variables in this file to make the variables taking efforts. Notice that when the bashrc is modified, you need to reopen a new terminal to apply the changes or use the following command:
For example, when you have already installed the ROS with
apt-get, you will be unable to launch
roscorewithout setting the variables:
You need to add the following script to
When the script is applied, you can use the command
whichto find the actual path of
The Linux shell is actually a kind of programming language, the
echocommand is to output contents on the screen, similar as the
Notice that the name of a variable starts with
$. This variable will tell Gazebo where to find the model files.
1、Ubuntu package manager
The Linux operating system uses the package manager to download and install softwares precompiled. Ubuntu uses
aptas the package manager. The basic usage:
sudo apt-get install package-name
2、Sources of package manager
Some of the packages such as ROS is not included in the official package sources, you can add the sources manually to install the third party packages with the package manager.
Here is the instruction of installing ROS on Ubuntu:
Notice that you must set up the keys before using the sources of ROS.
Set up the keys of ROS sources
You must use the following command to apply the sources modified
sudo apt-get update
3、Python package manager
The Python intepreter also includes a package manager for installing third party Python library. Since the ROS is partly based on Python, some Python packages are required to install.
The package manager of Python is pip, and should be installed through the following command:
sudo apt-get install python-pip
pip install package-name
When a "permission denied" error occurs, use the parameter
pip install package-name --user
Notice that you had better not run pip with sudo!
The developers can distribute the software in two kinds of forms: source code distribution and binary distribution. Many open-source softwares are distributed in the form of source code, and the users should compile the source code by themselves. Some components of the GAAS are also released with source codes and should be compiled into executable binary files to use e.g. the SLAM component.
2、cmake and makefile
Many open-source softwares are built with C/C++ programming language, and the source code files should be compiled and linked in the sequence of dependency. The UNIX-compatible systems (e.g. Linux) are using makefile to define compiling rules and dependencies. Use the command
maketo launch a makefile and compile the codes in sequence, and the files which have already been built will be skipped.
The C++ compiling toolchains of Ubuntu should be installed with the command:
sudo apt-get install build-essential
Use make to execute a makefile：
Here the "target" is defined by the makefile. For example, the following command can build the PX4 firmware and Gazebo simulator:
make posix_sitl_default gazebo
For most software, you can use a blank "target" directly:
Use the parameter
-jto compile in parallel with a number of subprocesses:
The parameter can take advantage of multi-core CPU, but the number of subprocesses cannot be more than actual CPU cores, or it may cause issues.
Cmake is used to detect the current platform, toolchains and shared libraries, configure and generate a makefile automatically. You can use apt-get to install cmake in Ubuntu.
3、Build and install open-source softwares
You can use the following steps to install most of the open-source softwares.
(1) Get the source code, you can use git to clone a repository on GitHub
git clone (the git address of the repository)
(2) Make a building directory. Since CMake do not provide the function of cleaning, the best practise is to make a building directory for CMake to generate temporary files. Usually the folder is named as
cd (directory of the repository)
(3) Generate makefile with CMake:
Here the current directory is the
builddirectory, and cmake will find the configuration file
CMakeLists.txt. This file is provided by the software developer, and usually the file is located in the directory of the software repository, which is the parent directory of
build. For most software, you can use the default parameters of CMake.
(4) Compile and install：
(Optional) sudo make install
For the shared library,
installcan install the compiled binary files into the system library for other programs to use.