# Ubuntu Development Environment

The following instructions set up a PX4 development environment on Ubuntu Linux 18.04 amd 20.04. This environment can be used to build PX4 for most PX4 targets:

TIP

This setup is supported by the PX4 dev team.

Note

The supported OS versions for PX4 development are Ubuntu Linux LTS (opens new window) 18.04 (Bionic Beaver) and 20.04 (Focal Fossa). For ROS (1) Ubuntu LTS 18.04 (only) is supported.

The instructions should also work on other Debian Linux based systems, but this is not verified/officially supported.

# Video Guide

This video shows how to install the toolchain for NuttX and simulation targets (as covered below) along with the basic testing covered in Building PX4 Software.

# Bash Scripts

Bash scripts are provided to help make it easy to install development environment for different target platforms. They are intended to be run on clean Ubuntu LTS installations.

Script Description
ubuntu.sh (opens new window) Installs Gazebo 9 and jMAVSim simulators and/or NuttX/Pixhawk tools.
Does not include dependencies for Fast DDS.
ubuntu_sim_ros_melodic.sh (opens new window) Installs ROS "Melodic" and PX4 on Ubuntu 18.04 LTS only.
Do not use on Ubuntu 20.04 or later!

Note

The scripts may not work if installed "on top" of an existing system, or on a different Ubuntu release.

# Gazebo, JMAVSim and NuttX (Pixhawk) Targets

Use the ubuntu.sh (opens new window) script to set up a development environment that includes Gazebo 9 and jMAVSim simulators, and/or the NuttX/Pixhawk toolchain.

WARNING

ROS users must follow the instructions for: ROS/Gazebo.

To install the toolchain:

  1. Download PX4 Source Code:
    git clone https://github.com/PX4/PX4-Autopilot.git --recursive
    
  2. Run the ubuntu.sh with no arguments (in a bash shell) to install everything:
    bash ./PX4-Autopilot/Tools/setup/ubuntu.sh
    
    • Acknowledge any prompts as the script progress.
    • You can use the --no-nuttx and --no-sim-tools options to omit the NuttX and/or simulation tools.
  3. Restart the computer on completion.
Information-only notes
  • The script installs Gazebo 9 (following gazebosim.org instructions (opens new window)). Gazebo 7, 8 are also supported but not recommended.
  • You can verify the NuttX installation by confirming the gcc version as shown:
     $arm-none-eabi-gcc --version
    
     arm-none-eabi-gcc (GNU Tools for Arm Embedded Processors 7-2017-q4-major) 7.2.1 20170904 (release) [ARM/embedded-7-branch revision 255204]
     Copyright (C) 2017 Free Software Foundation, Inc.
     This is free software; see the source for copying conditions.  There is NO
     warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    
  • You're going to need the PX4 source code anyway. But if you just wanted to set up the development environment without getting all the source code you could instead just download ubuntu.sh (opens new window) and requirements.txt (opens new window) and then run ubuntu.sh:
    wget https://raw.githubusercontent.com/PX4/PX4-Autopilot/main/Tools/setup/ubuntu.sh
    wget https://raw.githubusercontent.com/PX4/PX4-Autopilot/main/Tools/setup/requirements.txt
    bash ubuntu.sh
    

# Raspberry Pi

The following instructions explain how to set up a build toolchain for RasPi on Ubuntu 18.04.

WARNING

To build for Ubuntu 20.04 (focal) you must use docker (the GCC toolchain on Ubuntu 20.04 can build PX4, but the generated binary files are too new to run on actual Pi). For more information see PilotPi with Raspberry Pi OS Developer Quick Start > Alternative build method using docker.

To get the common dependencies for Raspberry Pi:

  1. Download ubuntu.sh (opens new window) and requirements.txt (opens new window) from the PX4 source repository (/Tools/setup/):
    wget https://raw.githubusercontent.com/PX4/PX4-Autopilot/main/Tools/setup/ubuntu.sh
    wget https://raw.githubusercontent.com/PX4/PX4-Autopilot/main/Tools/setup/requirements.txt
    
  2. Run ubuntu.sh in a terminal to get just the common dependencies:
    bash ubuntu.sh --no-nuttx --no-sim-tools
    
  3. Then setup an cross-compiler (either GCC or clang) as described in the following sections.

# GCC (armhf)

Ubuntu software repository provides a set of pre-compiled toolchains. Note that Ubuntu Focal comes up with gcc-9-arm-linux-gnueabihf as its default installation which is not fully supported, so we must manually install gcc-8-arm-linux-gnueabihf and set it as the default toolchain. This guide also applies to earlier Ubuntu releases (Bionic). The following instruction assumes you haven't installed any version of arm-linux-gnueabihf, and will set up the default executable with update-alternatives. Install them with the terminal command:

sudo apt-get install -y gcc-8-arm-linux-gnueabihf g++-8-arm-linux-gnueabihf

Set them as default:

sudo update-alternatives --install /usr/bin/arm-linux-gnueabihf-gcc arm-linux-gnueabihf-gcc /usr/bin/arm-linux-gnueabihf-gcc-8 100 --slave /usr/bin/arm-linux-gnueabihf-g++ arm-linux-gnueabihf-g++ /usr/bin/arm-linux-gnueabihf-g++-8
sudo update-alternatives --config arm-linux-gnueabihf-gcc

# GCC (aarch64)

If you want to build PX4 for ARM64 devices, this section is required.

sudo apt-get install -y gcc-8-aarch64-linux-gnu g++-8-aarch64-linux-gnu
sudo update-alternatives --install /usr/bin/aarch64-linux-gnu-gcc aarch64-linux-gnu-gcc /usr/bin/aarch64-linux-gnu-gcc-8 100 --slave /usr/bin/aarch64-linux-gnu-g++ aarch64-linux-gnu-g++ /usr/bin/aarch64-linux-gnu-g++-8
sudo update-alternatives --config aarch64-linux-gnu-gcc

# Clang (optional)

First install GCC (needed to use clang).

We recommend you to get clang from the Ubuntu software repository, as shown below:

sudo apt-get install clang

Example below for building PX4 firmware out of tree, using CMake.

cd <PATH-TO-PX4-SRC>
mkdir build/px4_raspberrypi_default_clang
cd build/px4_raspberrypi_default_clang
cmake \
-G"Unix Makefiles" \
-DCONFIG=px4_raspberrypi_default \
-UCMAKE_C_COMPILER \
-DCMAKE_C_COMPILER=clang \
-UCMAKE_CXX_COMPILER \
-DCMAKE_CXX_COMPILER=clang++ \
../..
make

# Detailed Information

Additional developer information for using PX4 on Raspberry Pi (including building PX4 natively) can be found here:

# ROS/Gazebo

This section explains how to install ROS "Melodic" and PX4 on Ubuntu 18.04.

WARNING

ROS builds are tied to specific Ubuntu versions! ROS Melodic can only install on Ubuntu 18.04.

To install the development toolchain:

  1. Download the script in a bash shell:
    wget https://raw.githubusercontent.com/PX4/Devguide/master/build_scripts/ubuntu_sim_ros_melodic.sh
    
  2. Run the script:
    bash ubuntu_sim_ros_melodic.sh
    
    You may need to acknowledge some prompts as the script progresses.

Note

  • ROS Melodic is installed with Gazebo9 by default.
  • Your catkin (ROS build system) workspace is created at ~/catkin_ws/.
  • The script uses instructions from the ROS Wiki "Melodic" Ubuntu page (opens new window).

# Fast DDS installation

eProsima Fast DDS (opens new window) is required if you're using PX4 with ROS2 (or some other RTPS/DDS system).

Follow the instructions in Fast DDS Installation to install it.

# Next Steps

Once you have finished setting up the command-line toolchain: