Skip to content

Setting up the environment

To start working with the nRF Connect SDK, you should set up your development environment. nRF Connect SDK is based on the Zephyr RTOS, which means most of the requirements for Zephyr are also suitable for the nRF Connect SDK. The only requirement that is not covered by the installation steps in Zephyr is the GN tool. This tool is needed only for Matter applications.

This guide shows you how to set up a command-line nRF Connect SDK development environment on Ubuntu, macOS, or Windows manually. For automatic installation, please refer to the Installing automatically page.

Select and Update OS

Install available updates for your operating system:

Select Start > Settings > Update & Security > Windows Update. Click Check for updates and install any that are available.

On macOS Mojave or later, select System Preferences... > Software Update. Click Update Now if necessary.

On other versions, see this Apple support topic.

This guide covers Ubuntu version 18.04 LTS and later.

sudo apt update
sudo apt upgrade

Install dependencies

Next, you’ll install some host dependencies using your package manager.

The current minimum required version for the main dependencies are:

Tool Min. Version
CMake 3.20.0
Python 3.8
Devicetree compiler 1.4.6

We use Chocolatey to install dependencies here. If Chocolatey isn’t an option, you can install dependencies from their respective websites and ensure the command line tools added in your PATH environment variable.

  1. Install chocolatey.

  2. Open a cmd.exe window as Administrator. To do so, press the Windows key Win , type cmd.exe, right-click the result, and choose Run as Administrator.

  3. Disable global confirmation to avoid having to confirm the installation of individual programs:

    choco feature enable -n allowGlobalConfirmation
    
  4. Use choco to install the required dependencies:

    choco install cmake --installargs 'ADD_CMAKE_TO_PATH=System'
    
    choco install ninja gperf python git dtc-msys2 wget unzip
    
  5. Close the window and open a new cmd.exe window as a regular user to continue.

Tip

To check the list of installed packages and their versions, run the following command:

choco list -lo
  1. Install Homebrew:

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    
  2. Use brew to install the required dependencies:

    brew install cmake ninja gperf python3 ccache qemu dtc wget libmagic
    

Tip

To check the versions of these dependencies installed, run the following command:

brew list --versions
  1. If using an Ubuntu version older than 22.04, it is necessary to add extra repositories to meet the minimum required versions for the main dependencies listed above. In that case, download, inspect and execute the Kitware archive script to add the Kitware APT repository to your sources list. A detailed explanation of kitware-archive.sh can be found here kitware third-party apt repository:

    wget https://apt.kitware.com/kitware-archive.sh
    
    sudo bash kitware-archive.sh
    
  2. Use apt to install the required dependencies:

    1
    2
    3
    4
    sudo apt install --no-install-recommends git cmake ninja-build gperf \
    ccache dfu-util device-tree-compiler wget \
    python3-dev python3-pip python3-setuptools python3-tk python3-wheel xz-utils file \
    make gcc gcc-multilib g++-multilib libsdl2-dev libmagic1
    
  3. Verify the versions of the main dependencies installed on your system by entering:

    cmake --version
    
    python3 --version
    
    dtc --version
    
Install GN tool for Matter

If you want to build Matter applications, additionally install the GN meta-build system. This system generates the Ninja files that the nRF Connect SDK uses.

To install the GN tool, complete the following steps:

  1. Download the latest version of the GN binary archive for Windows from the GN website.

  2. Extract the zip archive.

  3. Ensure that the GN tool is added to your PATH environment variable.

To install the GN tool, complete the following steps:

  1. Create the directory for the GN tool:

    mkdir ${HOME}/gn && cd ${HOME}/gn
    
  2. Download the GN binary archive and extract it by using the following commands:

    wget -O gn.zip https://chrome-infra-packages.appspot.com/dl/gn/gn/mac-arm64/+/latest
    
    unzip gn.zip
    
    rm gn.zip
    
    wget -O gn.zip https://chrome-infra-packages.appspot.com/dl/gn/gn/mac-amd64/+/latest
    
    unzip gn.zip
    
    rm gn.zip
    
  3. Add the location of the GN tool to the system PATH. For example, if you are using bash, run the following commands:

    1. Create the .bash_profile file if you do not have it already:

      touch ${HOME}/.bash_profile
      
    2. Add the location of the GN tool to .bash_profile:

      echo 'export PATH=${HOME}/gn:"$PATH"' >> ${HOME}/.bash_profile
      
      source ${HOME}/.bash_profile
      

To install the GN tool, complete the following steps:

  1. Create the directory for the GN tool:

    mkdir ${HOME}/gn && cd ${HOME}/gn
    
  2. Download the GN binary archive and extract it by using the following commands:

    wget -O gn.zip https://chrome-infra-packages.appspot.com/dl/gn/gn/linux-amd64/+/latest
    
    unzip gn.zip
    
    rm gn.zip
    
  3. Add the location of the GN tool to the system PATH. For example, if you are using bash, run the following commands:

    echo 'export PATH=${HOME}/gn:"$PATH"' >> ${HOME}/.bashrc
    
    source ${HOME}/.bashrc
    

Install west

To manage the combination of repositories and versions, the nRF Connect SDK uses Zephyr’s west.

To install west, reopen the command prompt window as an administrator to ensure that Python is initialized, and complete the following step:

Enter the following command in a command-line window:

pip3 install west

Note

Ensure the west location is added to the path in environmental variables.

Enter the following command in a terminal window:

pip3 install west

Enter the following command in a terminal window:

pip3 install --user west
echo 'export PATH=~/.local/bin:"$PATH"' >> ~/.bashrc
source ~/.bashrc

Get the code

To help you quickly build and run the samples on nRF52840 Connect Kit, we maintain a public repository named ncs-playground which consists of nRF Connect SDK manifest repositories, additional hardware drivers and tested samples, etc.

To clone the repositories, complete the following steps:

  1. Initialize the workspace folder (my-workspace) where all the required repositories will be cloned:

    west init -m https://github.com/makerdiary/ncs-playground --mr main my-workspace
    

    Tip

    You can initialize west with the revision of ncs-playground that you want to check out. For example, to check out the v2.4.0 release, enter the following command:

    west init -m https://github.com/makerdiary/ncs-playground --mr v2.4.0 my-workspace
    
  2. Enter the following commands to clone the project repositories:

    cd my-workspace
    
    west update
    

    After all the repositories updated, your workspace folder now looks similar to this:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    my-workspace
    |___ .west
    |___ bootloader
    |___ ncs-playground
    |___ modules
    |___ nrf
    |___ nrfxlib
    |___ zephyr
    |___ ...
    
  3. Export a Zephyr CMake package. This allows CMake to automatically load the boilerplate code required for building nRF Connect SDK applications:

    west zephyr-export
    

Install additional Python dependencies

The nRF Connect SDK requires additional Python packages to be installed. Use the following commands to install the requirements for each repository.

Enter the following command in a command-line window in the my-workspace folder:

pip3 install -r zephyr/scripts/requirements.txt
pip3 install -r nrf/scripts/requirements.txt
pip3 install -r bootloader/mcuboot/scripts/requirements.txt

Enter the following command in a terminal in the my-workspace folder:

pip3 install -r zephyr/scripts/requirements.txt
pip3 install -r nrf/scripts/requirements.txt
pip3 install -r bootloader/mcuboot/scripts/requirements.txt

Enter the following command in a terminal in the my-workspace folder:

pip3 install --user -r zephyr/scripts/requirements.txt
pip3 install --user -r nrf/scripts/requirements.txt
pip3 install --user -r bootloader/mcuboot/scripts/requirements.txt

Install Zephyr SDK

The Zephyr Software Development Kit (SDK) contains toolchains for each of Zephyr’s supported architectures, which include a compiler, assembler, linker and other programs required to build Zephyr applications.

It also contains additional host tools, such as custom QEMU and OpenOCD builds that are used to emulate, flash and debug Zephyr applications.

  1. Open a cmd.exe window by pressing the Windows key typing cmd.exe.
  2. Download the Zephyr SDK bundle:

    cd %HOMEPATH%
    
    wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.1/zephyr-sdk-0.16.1_windows-x86_64.7z
    
  3. Extract the Zephyr SDK bundle archive:

    7z x zephyr-sdk-0.16.1_windows-x86_64.7z
    

    Note

    It is recommended to extract the Zephyr SDK bundle at one of the following locations:

    • %HOMEPATH%
    • %PROGRAMFILES%

    The Zephyr SDK bundle archive contains the zephyr-sdk-0.16.1 directory and, when extracted under %HOMEPATH%, the resulting installation path will be %HOMEPATH%\zephyr-sdk-0.16.1.

  4. Run the Zephyr SDK bundle setup script:

    cd zephyr-sdk-0.16.1
    
    setup.cmd
    

    Note

    You only need to run the setup script once after extracting the Zephyr SDK bundle.

    You must rerun the setup script if you relocate the Zephyr SDK bundle directory after the initial setup.

  1. Download and verify the Zephyr SDK bundle:

    cd ~
    
    wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.1/zephyr-sdk-0.16.1_macos-x86_64.tar.xz
    
    wget -O - https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.1/sha256.sum | shasum --check --ignore-missing
    

    If your host architecture is 64-bit ARM (Apple Silicon, also known as M1), replace x86_64 with aarch64 in order to download the 64-bit ARM macOS SDK.

  2. Extract the Zephyr SDK bundle archive:

    tar xvf zephyr-sdk-0.16.1_macos-x86_64.tar.xz
    

    Note

    It is recommended to extract the Zephyr SDK bundle at one of the following locations:

    • $HOME
    • $HOME/.local
    • $HOME/.local/opt
    • $HOME/bin
    • /opt
    • /usr/local

    The Zephyr SDK bundle archive contains the zephyr-sdk-0.16.1 directory and, when extracted under $HOME, the resulting installation path will be $HOME/zephyr-sdk-0.16.1.

  3. Run the Zephyr SDK bundle setup script:

    cd zephyr-sdk-0.16.1
    
    ./setup.sh
    

    Note

    You only need to run the setup script once after extracting the Zephyr SDK bundle.

    You must rerun the setup script if you relocate the Zephyr SDK bundle directory after the initial setup.

  1. Download and verify the Zephyr SDK bundle:

    cd ~
    
    wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.1/zephyr-sdk-0.16.1_linux-x86_64.tar.xz
    
    wget -O - https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.1/sha256.sum | shasum --check --ignore-missing
    

    If your host architecture is 64-bit ARM (for example, Raspberry Pi), replace x86_64 with aarch64 in order to download the 64-bit ARM Linux SDK.

  2. Extract the Zephyr SDK bundle archive:

    tar xvf zephyr-sdk-0.16.1_linux-x86_64.tar.xz
    

    Note

    It is recommended to extract the Zephyr SDK bundle at one of the following locations:

    • $HOME
    • $HOME/.local
    • $HOME/.local/opt
    • $HOME/bin
    • /opt
    • /usr/local

    The Zephyr SDK bundle archive contains the zephyr-sdk-0.16.1 directory and, when extracted under $HOME, the resulting installation path will be $HOME/zephyr-sdk-0.16.1.

  3. Run the Zephyr SDK bundle setup script:

    cd zephyr-sdk-0.16.1
    
    ./setup.sh
    

    Note

    You only need to run the setup script once after extracting the Zephyr SDK bundle.

    You must rerun the setup script if you relocate the Zephyr SDK bundle directory after the initial setup.

  4. Install udev rules, which allow you to flash most Zephyr boards as a regular user:

    sudo cp ~/zephyr-sdk-0.16.1/sysroots/x86_64-pokysdk-linux/usr/share/openocd/contrib/60-openocd.rules /etc/udev/rules.d
    
    sudo udevadm control --reload