# Ubuntu LTS/Debian Linux 的开发环境

Ubuntu linux lts (opens new window)(16.04)是标准的/首选的 Linux 开发操作系统。 Linux允许您构建所有PX4目标(基于NuttX的硬件、高通骁龙飞控硬件、基于Linux的硬件、仿真、ROS)。


This setup is supported by the PX4 dev team.


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.

# 一键安装脚本


@用户应先加入组 ”dialout“:

# 权限设置

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!


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

# ROS/Gazebo

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.


users must follow the instructions for: ROS/Gazebo.

To install the toolchain:

  1. ubuntu_sim_common_deps.sh通用依赖jMAVSim 模拟器
    git clone https://github.com/PX4/PX4-Autopilot.git --recursive
  2. 运行 bash 脚本(比如运行 ubuntu_sim.sh ): bash source ubuntu_sim.sh 所有弹出的提示均确认通过。
    bash ./PX4-Autopilot/Tools/setup/ubuntu.sh
    • 在安装过程中确认并通过所有的提示。
    • 你可以通过传输参数--no-nuttx--no-sim-tools 来跳过 nuttx 和/或 仿真器工具的安装。
  3. 完成后重新启动计算机。

Information-only notes

  • ** Note** PX4兼容Gazebo7、8和9。 上面的 安装说明 (opens new window) 是关于安装 Gazebo 9 的。
  • 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
  • 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/master/Tools/setup/ubuntu.sh
    wget https://raw.githubusercontent.com/PX4/PX4-Autopilot/master/Tools/setup/requirements.txt
    bash ubuntu.sh

:::<!-- Do we need to add to our scripts or can we assume correct version installs over? Remove any old versions of the arm-none-eabi toolchain.

sudo apt-get remove gcc-arm-none-eabi gdb-arm-none-eabi binutils-arm-none-eabi gcc-arm-embedded
sudo add-apt-repository --remove ppa:team-gcc-arm-embedded/ppa


# 通用依赖

jMAVSim Simulation 安装依赖。


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.

本节解释如何安装 ROS/Gazebo ("Melodic") 以便与PX4一起使用。

  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/master/Tools/setup/ubuntu.sh
    wget https://raw.githubusercontent.com/PX4/PX4-Autopilot/master/Tools/setup/requirements.txt
  2. ubuntu_sim_nuttx.shubuntu_sim.sh + NuttX 工具。
    bash ubuntu.sh --no-nuttx --no-sim-tools
  3. Then setup an cross-compiler (either GCC or clang) as described in the following sections.

# 如何使用脚本

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 usermod -a -G dialout $USER

sudo apt-get remove modemmanager

# jMAVSim

sudo apt-get install protobuf-compiler libeigen3-dev libopencv-dev -y

sudo apt-get update -y
sudo apt-get install git zip qtcreator cmake \
    build-essential genromfs ninja-build exiftool vim-common -y
# Required python packages
sudo apt-get install python-argparse \
    python-empy python-toml python-numpy python-yaml \
    python-dev python-pip -y
sudo -H pip install --upgrade pip 
sudo -H pip install pandas jinja2 pyserial cerberus

# Gazebo

First install GCC (needed to use clang).

sudo apt-get update

# optional python tools
sudo -H pip install pyulog

sudo apt-get install ros-kinetic-desktop-full -y

git clone https://github.com/raspberrypi/tools.git ${HOME}/rpi-tools
# test compiler
$HOME/rpi-tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-gcc -v
# permanently update PATH variable by modifying ~/.profile
echo 'export PATH=$PATH:$HOME/rpi-tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin' >> ~/.profile
# update PATH variable only for this session
export PATH=$PATH:$HOME/rpi-tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin

# Detailed Information

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

# FastRTPS 安装

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


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. 下载脚本
    ROS Gazebo: http://wiki.ros.org/kinetic/Installation/Ubuntu


  • ROS Kinetic 默认与 Gazebo 7 一起安装(为了简化 ROS 的开发,我们使用的默认而不是 Gazebo 8)。
  • 你的 catkin (ROS 构建系统)工作目录生成在**~/catkin_ws/**。
  • The script uses instructions from the ROS Wiki "Melodic" Ubuntu page (opens new window).

# 模拟器依赖

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.

# Gazebo dependencies

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