This guide details how to build CARLA from source on Linux. There are two parts. Part one details system requirements and installations of required software, and part two details how to actually build and run CARLA.
The build process is long (4 hours or more) and involves several kinds of software. It is highly recommended to read through the guide fully before starting.
If you come across errors or difficulties then have a look at the F.A.Q. page which offers solutions for the most common complications. Alternatively, use the CARLA forum to post any queries you may have.
- Part One: Prerequisites
- Part Two: Build CARLA
Part One: Prerequisites
- Ubuntu 18.04. CARLA provides support for previous Ubuntu versions up to 16.04. However proper compilers are needed for Unreal Engine to work properly. Dependencies for Ubuntu 18.04 and previous versions are listed separatedly below. Make sure to install the ones corresponding to your system.
- 130 GB disk space. Carla will take around 31 GB and Unreal Engine will take around 91 GB so have about 130 GB free to account for both of these plus additional minor software installations.
- An adequate GPU. CARLA aims for realistic simulations, so the server needs at least a 6 GB GPU although 8 GB is recommended. A dedicated GPU is highly recommended for machine learning.
- Two TCP ports and good internet connection. 2000 and 2001 by default. Make sure that these ports are not blocked by firewalls or any other applications.
CARLA requires many different kinds of software to run. Some are built during the CARLA build process itself, such as Boost.Python. Others are binaries that should be installed before starting the build (cmake, clang, different versions of Python, etc.). To install these requirements, run the following commands:
sudo apt-get update && sudo apt-get install wget software-properties-common && sudo add-apt-repository ppa:ubuntu-toolchain-r/test && wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add - && sudo apt-add-repository "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-8 main" && sudo apt-get update
The following commands depend on your Ubuntu version. Make sure to choose accordingly.
sudo apt-get install build-essential clang-8 lld-8 g++-7 cmake ninja-build libvulkan1 python python-pip python-dev python3-dev python3-pip libpng-dev libtiff5-dev libjpeg-dev tzdata sed curl unzip autoconf libtool rsync libxml2-dev git && pip2 install --user setuptools && pip3 install --user -Iv setuptools==47.3.1 && pip2 install --user distro && pip3 install --user distro
Previous Ubuntu versions.
sudo apt-get install build-essential clang-8 lld-8 g++-7 cmake ninja-build libvulkan1 python python-pip python-dev python3-dev python3-pip libpng16-dev libtiff5-dev libjpeg-dev tzdata sed curl unzip autoconf libtool rsync libxml2-dev git && pip2 install --user setuptools && pip3 install --user -Iv setuptools==47.3.1 && pip2 install --user distro && pip3 install --user distro
All Ubuntu systems.
To avoid compatibility issues between Unreal Engine and the CARLA dependencies, use the same compiler version and C++ runtime library to compile everything. The CARLA team uses clang-8 and LLVM's libc++. Change the default clang version to compile Unreal Engine and the CARLA dependencies.
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/lib/llvm-8/bin/clang++ 180 && sudo update-alternatives --install /usr/bin/clang clang /usr/lib/llvm-8/bin/clang 180
Starting with version 0.9.12, CARLA uses a modified fork of Unreal Engine 4.26. This fork contains patches specific to CARLA.
Be aware that to download this fork of Unreal Engine, you need to have a GitHub account linked to Unreal Engine's account. If you don't have this set up, please follow this guide before going any further.
1. Clone the content for CARLA's fork of Unreal Engine 4.26 to your local computer:
git clone --depth 1 -b carla https://github.com/CarlaUnreal/UnrealEngine.git ~/UnrealEngine_4.26
2. Navigate into the directory where you cloned the repository:
3. Make the build. This may take an hour or two depending on your system.
./Setup.sh && ./GenerateProjectFiles.sh && make
4. Open the Editor to check that Unreal Engine has been installed properly.
cd ~/UnrealEngine_4.26/Engine/Binaries/Linux && ./UE4Editor
Part Two: Build CARLA
Downloading aria2 with
sudo apt-get install aria2 will speed up the following commands.
Clone the CARLA repository
The button above will take you to the official repository of the project. Either download from there and extract it locally or clone it using the following command:
git clone https://github.com/carla-simulator/carla
master branch contains the current release of CARLA with the latest fixes and features. Previous CARLA versions are tagged with the version name. Always remember to check the current branch in git with the command
You will need to download the latest assets to work with the current version of CARLA. We provide a script to automate this process. To use the script, run the following command in the CARLA root folder:
The assets will be downloaded and extracted to the appropriate location.
To download the assets currently in development, visit Update CARLA and read Get development assets.
To download the assets for a specific version of CARLA:
- From the root CARLA directory, navigate to
\Util\ContentVersions.txt. This document contains the links to the assets for all CARLA releases.
- Extract the assets in
Unreal\CarlaUE4\Content\Carla. If the path doesn't exist, create it.
- Extract the file with a command similar to the following:
tar -xvzf <assets_file_name>.tar.gz.tar -C C:\path\to\carla\Unreal\CarlaUE4\Content\Carla
Set Unreal Engine environment variable
For CARLA to find the correct installation of Unreal Engine, we need to set the CARLA environment variable.
To set the variable for this session only:
To set the variable so it persists across sessions:
gedit ~/.bashrc # or gedit ~/.profile
2. Add the following line to the bottom of the file:
3. Save the file and reset the terminal.
This section outlines the commands to build CARLA. All commands should be run in the root CARLA folder.
There are two parts to the build process for CARLA, compiling the client and compiling the server.
Make sure to run
make PythonAPI to prepare the client and
make launch for the server.
make LibCarla will prepare the CARLA library to be imported anywhere.
1. Compile the Python API client:
The Python API client grants control over the simulation. Compilation of the Python API client is required the first time you build CARLA and again after you perform any updates. After the client is compiled, you will be able to run scripts to interact with the simulation.
The following command compiles the Python API client:
Optionally, to compile the PythonAPI for Python 2, run the following command in the root CARLA directory.
make PythonAPI ARGS="--python-version=2"
Note that when the compilation is done, you may see a successful output in the terminal even if the compilation of the Python API client was unsuccessful. Check for any errors in the terminal output and check that a
.egg file exists in
PythonAPI\carla\dist. If you come across any errors, check the F.A.Q. or post in the CARLA forum.
2. Compile the server:
The following command compiles and launches Unreal Engine. Run this command each time you want to launch the server or use the Unreal Engine editor:
The project may ask to build other instances such as
UE4Editor-Carla.dll the first time. Agree in order to open the project. During the first launch, the editor may show warnings regarding shaders and mesh distance fields. These take some time to be loaded and the map will not show properly until then.
3. Start the simulation:
Press Play to start the server simulation. The camera can be moved with
WASD keys and rotated by clicking the scene while moving the mouse around.
Test the simulator using the example scripts inside
PythonAPI\examples. With the simulator running, open a new terminal for each script and run the following commands to spawn some life into the town and create a weather cycle:
# Terminal A cd PythonAPI/examples python3 -m pip install -r requirements.txt python3 generate_traffic.py # Terminal B cd PythonAPI/examples python3 dynamic_weather.py
If you encounter the error
ModuleNotFoundError: No module named 'carla' while running a script, you may be running a different version of Python than the one used to install the client. Go to
PythonAPI\carla\dist and check the version of Python used in the
If the simulation is running at a very low FPS rate, go to
Edit -> Editor preferences -> Performance in the Unreal Engine editor and disable
Use less CPU when in background.
Other make commands
There are more
make commands that you may find useful. Find them in the table below:
||Prints all available commands.|
||Launches CARLA server in Editor window.|
||Builds the CARLA client.|
||Prepares the CARLA library to be imported anywhere.|
||Builds CARLA and creates a packaged version for distribution.|
||Deletes all the binaries and temporals generated by the build system.|
Below is a summary of the requirements and commands needed to build CARLA on Linux:
# Make sure to meet the minimum requirements # Read the complete documentation to understand each step # Install dependencies sudo apt-get update && sudo apt-get install wget software-properties-common && sudo add-apt-repository ppa:ubuntu-toolchain-r/test && wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add - && sudo apt-add-repository "deb http://apt.llvm.org/$(lsb_release -c --short)/ llvm-toolchain-$(lsb_release -c --short)-8 main" && sudo apt-get update # Additional dependencies for Ubuntu 18.04 sudo apt-get install build-essential clang-8 lld-8 g++-7 cmake ninja-build libvulkan1 python python-pip python-dev python3-dev python3-pip libpng-dev libtiff5-dev libjpeg-dev tzdata sed curl unzip autoconf libtool rsync libxml2-dev git && pip2 install --user setuptools && pip3 install --user -Iv setuptools==47.3.1 # Additional dependencies for previous Ubuntu versions sudo apt-get install build-essential clang-8 lld-8 g++-7 cmake ninja-build libvulkan1 python python-pip python-dev python3-dev python3-pip libpng16-dev libtiff5-dev libjpeg-dev tzdata sed curl unzip autoconf libtool rsync libxml2-dev git && pip2 install --user setuptools && pip3 install --user -Iv setuptools==47.3.1 && pip2 install --user distro && pip3 install --user distro # Change default clang version sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/lib/llvm-8/bin/clang++ 180 && sudo update-alternatives --install /usr/bin/clang clang /usr/lib/llvm-8/bin/clang 180 # Get a GitHub and an Unreal Engine account, and link both # Download Unreal Engine 4.24 git clone --depth 1 -b carla https://github.com/CarlaUnreal/UnrealEngine.git ~/UnrealEngine_4.26 cd ~/UnrealEngine_4.26 # Build Unreal Engine ./Setup.sh && ./GenerateProjectFiles.sh && make # Open the Unreal Engine Editor to check everything works properly cd ~/UnrealEngine_4.26/Engine/Binaries/Linux && ./UE4Editor # Clone the CARLA repository git clone https://github.com/carla-simulator/carla # Get the CARLA assets cd ~/carla ./Update.sh # Set the environment variable export UE4_ROOT=~/UnrealEngine_4.26 # make the CARLA client make PythonAPI # make the CARLA server make launch # Press play in the Editor to initialize the server # Run example scripts to test CARLA # Terminal A cd PythonAPI/examples python3 -m pip install -r requirements.txt python3 generate_traffic.py # Terminal B cd PythonAPI/examples python3 generate_traffic.py python3 dynamic_weather.py # Optionally, to compile the PythonAPI for Python2 make PythonAPI ARGS="--python-version=2"
Up next, learn how to update the CARLA build or take your first steps in the simulation, and learn some core concepts.