---
title: "Build the source code"
url: "https://docs.yugabyte.com/stable/contribute/core-database/build-from-src-almalinux/"
---

# Build the source code

Build YugabyteDB from source code on AlmaLinux.

Build the source code.

- [AlmaLinux](/stable/contribute/core-database/build-from-src-almalinux/)
- [macOS](/stable/contribute/core-database/build-from-src-macos/)
- [Ubuntu](/stable/contribute/core-database/build-from-src-ubuntu/)

Note

AlmaLinux 8 is the recommended Linux development platform for YugabyteDB.

## TLDR

The commands below assume the following:

- You have sudo access.
- You are using a bash or zsh shell.
- You are running the commands as the user who will be doing development.

```sh
# Modify to your preference:
shellrc=~/.bashrc

sudo dnf update -y
sudo dnf groupinstall -y 'Development Tools'
sudo dnf -y install epel-release
packages=(
  ccache
  golang
  java-1.8.0-openjdk
  libatomic
  maven
  npm
  patchelf
  python3.11
  rsync
)
sudo dnf -y install "${packages[@]}"
sudo alternatives --set python3 /usr/bin/python3.9
latest_zip_url=$(curl -Ls "https://api.github.com/repos/ninja-build/ninja/releases/latest" \
                 | grep browser_download_url | grep ninja-linux.zip | cut -d \" -f 4)
curl -Ls "$latest_zip_url" | zcat | sudo tee /usr/local/bin/ninja >/dev/null
sudo chmod +x /usr/local/bin/ninja
sudo mkdir /opt/yb-build

# If you'd like to use an unprivileged user for development, manually
# run/modify instructions from here onwards (change $USER, make sure shell
# variables are set appropriately when switching users).
sudo chown "$USER" /opt/yb-build
mkdir ~/tools
curl -L "https://github.com/Kitware/CMake/releases/download/v3.31.0/cmake-3.31.0-linux-x86_64.tar.gz" | tar xzC ~/tools
source <(echo 'export PATH="$HOME/tools/cmake-3.31.0-linux-x86_64/bin:$PATH"' \
         | tee -a "$shellrc")
source <(echo 'export YB_CCACHE_DIR="$HOME/.cache/yb_ccache"' \
         | tee -a "$shellrc")

git clone https://github.com/yugabyte/yugabyte-db
cd yugabyte-db
./yb_release
```

## Detailed instructions

Update and install basic development packages as follows:

```sh
sudo dnf update -y
sudo dnf groupinstall -y 'Development Tools'
sudo dnf -y install epel-release libatomic rsync
```

### /opt/yb-build

By default, when running build, third-party libraries are not built, and pre-built libraries are downloaded. The build scripts automatically install these in directories under `/opt/yb-build`. In order for the build script to write under those directories, it needs proper permissions. One way to do that is as follows:

```sh
sudo mkdir /opt/yb-build
sudo chown "$USER" /opt/yb-build
```

Alternatively, specify the build options `--no-download-thirdparty`. Note that those options may require additional, undocumented steps.

### Python 3

Python 3.11 or higher is required.

The following example installs Python 3.11.

```sh
sudo dnf install -y python3.11
```

Set this as the default python3, if desired. It is only necessary that python3.11 be in the PATH, it need not be the default python.

```sh
sudo alternatives --set python3 /usr/bin/python3.11
sudo alternatives --display python3
python3 -V
```

### CMake 3

[CMake](https://cmake.org "CMake") 3.31.0 or higher is required.

The CMake version in the package manager is too old, so manually download a release as follows:

```sh
mkdir ~/tools
curl -L "https://github.com/Kitware/CMake/releases/download/v3.31.0/cmake-3.31.0-linux-x86_64.tar.gz" | tar xzC ~/tools
# Also add the following line to your .bashrc or equivalent.
export PATH="$HOME/tools/cmake-3.31.0-linux-x86_64/bin:$PATH"
```

### Java

YugabyteDB core is written in C and C++, but the repository contains Java code needed to run some tests and sample applications. To build the Java part, you need:

- Java Development Kit (JDK) 8 or 11.
- [Apache Maven](https://maven.apache.org/ "Apache Maven") 3.3 or later.

Install the following packages to satisfy the preceding requirements:

```sh
sudo dnf install -y java-1.8.0-openjdk maven
```

### yugabyted-ui

yugabyted-ui is a UI for [yugabyted](/stable/reference/configuration/yugabyted "yugabyted"). By default, it is not built unless the corresponding build option is specified or a release package is being built. To build it, [npm](https://www.npmjs.com "npm") and [Go](https://go.dev "Go") 1.20 or higher are required.

```sh
sudo dnf install -y npm golang
```

### Ninja (optional)

Install [Ninja](https://ninja-build.org "Ninja") for faster builds as follows:

The latest release can be downloaded:

```sh
latest_zip_url=$(curl -Ls "https://api.github.com/repos/ninja-build/ninja/releases/latest" \
                 | grep browser_download_url | grep ninja-linux.zip | cut -d \" -f 4)
curl -Ls "$latest_zip_url" | zcat | sudo tee /usr/local/bin/ninja >/dev/null
sudo chmod +x /usr/local/bin/ninja
```

### Ccache (optional)

Install and configure [Ccache](https://ccache.dev "Ccache") for faster builds as follows:

```sh
sudo dnf install -y ccache
# Also add the following line to your .bashrc or equivalent.
export YB_CCACHE_DIR="$HOME/.cache/yb_ccache"
```

## Build the code

Assuming [this repository](https://github.com/yugabyte/yugabyte-db "this repository") is checked out in `~/code/yugabyte-db`, do the following:

```sh
cd ~/code/yugabyte-db
./yb_build.sh release
```

The command above will build the release configuration, add the binaries into the `build/release-<compiler>-dynamic-ninja` directory, and create a `build/latest` symlink to that directory.

Note

If you see errors, such as `internal compiler error: Killed`, the system has probably run out of memory. Try again by running the build script with less concurrency, for example, `-j1`.

Note

If you get an error message such as

> ValueError: Found no third-party release archives to download for OS type ubuntu20.04, compiler type matching gcc11, architecture x86\_64, is\_linuxbrew=False. See more details above.

it means that there is no [third-party download](#opt-yb-build "third-party download") available for that build configuration. Check the output that precedes the message for supported configurations.

For more details about building and testing, refer to [Build and test](/stable/contribute/core-database/build-and-test "Build and test").

### Build release package (optional)

Perform the following steps to build a release package:

1. [Satisfy requirements for building yugabyted-ui](#yugabyted-ui "Satisfy requirements for building yugabyted-ui").
2. Install patchelf:
   
   ```sh
   sudo dnf install -y patchelf
   ```
3. Run the `yb_release` script using the following command:
   
   ```sh
   ./yb_release
   ```
   
   ```output.sh
   ......
   2023-02-14 04:14:16,092 [yb_release.py:299 INFO] Generated a package at '/home/user/code/yugabyte-db/build/yugabyte-2.17.2.0-b8e42eecde0e45a743d51e244dbd9662a6130cd6-release-clang15-centos-x86_64.tar.gz'
   ```

Note

The build may fail with "too many open files". In that case, increase the nofile limit in `/etc/security/limits.conf` as follows:

```sh
echo "* - nofile 1048576" | sudo tee -a /etc/security/limits.conf
```

Start a new shell session, and check the limit increase with `ulimit -n`.
