nrfutil toolchain-manager env does not set ZEPHYR_BASE

I am trying to setup a NRF SDK development environment on the terminal on Ubuntu (I already successfully setup using VSCode), and I am trying to use nrfutil toolchain-manager env --as-script for that.

But when I try to build my project using west, it fails with unknown command "build".

Which I is due to missing ZEPHYR_BASE environment variable.

From  How can I enable west build in Git Bash? I supposed the command should have set this variable. If I open a "NRF Connect" terminal in VSCode, the env var is set correctly, and the command VSCode executes when building does not pass the ZEPHYR_BASE in `-z`.

It may be related that the toolchain was installed by VSCode, and I later installed nrfutil toolchain-manager, which made me run into  nrfutil: Error: Failed to find default toolchain , but I fixed it by running nrfutil toolchain-manager install --ncs-version v3.0.2. I tried installing another toolchain version (nrfutil toolchain-manager install --ncs-version v3.0.1), but it displayed the same problem.

Version information

  • nrfutil 8.1.0 (34e21a1 2025-07-29)
  • nrfutil-toolchain-manager 0.15.0 (30dc218 2024-06-12)
  • ncs version v3.0.2

PS: When I tried to post this ticket a error popup appeared in the top right saying only "Could not create ticked". Looking in chrome devtools, there was a request with a 403 response, including a page with "Sorry, you have been blocked" in big letter, but with "Please enable cookies" in small letters before it. Trying to enable cookies didn't solve it. I am now trying to delete parts of my post to see if anything here is triggering it.

Parents
  • Hi

    You need to set source zephyr/zephyr-env.sh as seen here

    Regards

    Runar

  • Sorry for the late reply. The source of my confusion was that I thought both the SDK and the toolchain were handled by `nrfutil toolchain-manager`, but that does not appear to be the case. I am trying to avoid hardcoding the SDK path.

    However, I discovered that there is an `nrfutil sdk-manager`, which manages both the SDK and the toolchains. It does not appear to have an equivalent of `nrfutil toolchain-manager env` for the SDK, but it does at least allow you to query the SDK path, and therefore find the path to `zephyr-env.sh`. So I made the following script for setting up the NCS environment (it relies on `jq` for parsing the JSON output of `nrfutil sdk-manager list --json`):

    #!/bin/sh
    # Usage: source ./ncd_env.sh
    # This script finds the first available nRF Connect SDK version and directory,
    # sources its environment, and then sources zephyr/zephyr-env.sh in that SDK.
    
    find_and_source_ncs_env() {
        # Get the JSON from nrfutil
        local json
        json="$(nrfutil sdk-manager list --json)"
    
        # Extract the first valid dir/version pair
        local result
        result=$(echo "$json" | jq -r '[.data.versions[] | {dir: (.dirNames[0] // null), version} | select(.dir != null and .version != null)][0] | @sh "version=\(.version) dir=\(.dir)"')
        eval "$result"  # sets $version and $dir
    
        if [ -n "$version" ] && [ -n "$dir" ]; then
            eval "$(nrfutil sdk-manager toolchain env --ncs-version "$version" --as-script sh)"
            # Source zephyr-env.sh if it exists
            if [ -f "$dir/zephyr/zephyr-env.sh" ]; then
                # shellcheck source=/dev/null
                . "$dir/zephyr/zephyr-env.sh"
                echo "Sourced env for ncs version $version"
            else
                echo "zephyr-env.sh not found at $dir/zephyr/zephyr-env.sh"
                return 2
            fi
        else
            echo "No valid version or directory found."
            return 1
        fi
    }
    
    find_and_source_ncs_env

Reply
  • Sorry for the late reply. The source of my confusion was that I thought both the SDK and the toolchain were handled by `nrfutil toolchain-manager`, but that does not appear to be the case. I am trying to avoid hardcoding the SDK path.

    However, I discovered that there is an `nrfutil sdk-manager`, which manages both the SDK and the toolchains. It does not appear to have an equivalent of `nrfutil toolchain-manager env` for the SDK, but it does at least allow you to query the SDK path, and therefore find the path to `zephyr-env.sh`. So I made the following script for setting up the NCS environment (it relies on `jq` for parsing the JSON output of `nrfutil sdk-manager list --json`):

    #!/bin/sh
    # Usage: source ./ncd_env.sh
    # This script finds the first available nRF Connect SDK version and directory,
    # sources its environment, and then sources zephyr/zephyr-env.sh in that SDK.
    
    find_and_source_ncs_env() {
        # Get the JSON from nrfutil
        local json
        json="$(nrfutil sdk-manager list --json)"
    
        # Extract the first valid dir/version pair
        local result
        result=$(echo "$json" | jq -r '[.data.versions[] | {dir: (.dirNames[0] // null), version} | select(.dir != null and .version != null)][0] | @sh "version=\(.version) dir=\(.dir)"')
        eval "$result"  # sets $version and $dir
    
        if [ -n "$version" ] && [ -n "$dir" ]; then
            eval "$(nrfutil sdk-manager toolchain env --ncs-version "$version" --as-script sh)"
            # Source zephyr-env.sh if it exists
            if [ -f "$dir/zephyr/zephyr-env.sh" ]; then
                # shellcheck source=/dev/null
                . "$dir/zephyr/zephyr-env.sh"
                echo "Sourced env for ncs version $version"
            else
                echo "zephyr-env.sh not found at $dir/zephyr/zephyr-env.sh"
                return 2
            fi
        else
            echo "No valid version or directory found."
            return 1
        fi
    }
    
    find_and_source_ncs_env

Children
No Data
Related