Set Up Raspberry Pi Pico SDK on Ubuntu 22.04

Set Up Raspberry Pi Pico SDK on Ubuntu 22.04

The Raspberry Pi Pico SDK is a collection of libraries, headers, and tools that allows to develop programs for the RP2040 based devices such as the Raspberry Pi Pico using C, C++ or assembly language.

This tutorial explains how to set up Raspberry Pi Pico SDK on Ubuntu 22.04.

Prepare environment

Make sure you have installed build-essential package in your system.

sudo apt update
sudo apt install -y build-essential

You also need to install:

No.SoftwareInstallation instructions
3.Arm GNU ToolchainRead

Install SDK

Clone the Raspberry Pi Pico SDK repository:

sudo git clone /opt/pico-sdk

Initialize submodules:

sudo git -C /opt/pico-sdk submodule update --init

Set the PICO_SDK_PATH environment variable, which specifies where SDK is installed:

echo 'export PICO_SDK_PATH=/opt/pico-sdk' | sudo tee -a /etc/profile.d/

To make changes to take effect, logout and login to your system or run the following command to apply the changes immediately:

source /etc/profile.d/

Build program

Create a new directory to store project files and navigate to this directory:

mkdir helloworld && cd helloworld

Create a main.c file:

nano main.c

Once the file is opened, add the following lines of code:


#include <stdio.h>
#include <pico/stdlib.h>

int main()

    while (true) {
        printf("Hello world\n");

Create a CMakeLists.txt file:

nano CMakeLists.txt

Add the following content:


cmake_minimum_required(VERSION 3.13)


project(myapp C CXX ASM)



add_executable(${PROJECT_NAME} main.c)


target_link_libraries(${PROJECT_NAME} pico_stdlib)

pico_enable_stdio_usb(${PROJECT_NAME} 1)
pico_enable_stdio_uart(${PROJECT_NAME} 0)

Create a build directory and navigate to it:

mkdir build && cd build

Prepare CMake build directory by running the following command:

cmake ..

Now run the make command to build program:

make -j$(nproc)

Using the ls command, you can check a list of generated files.

CMakeCache.txt  cmake_install.cmake  generated  myapp.bin  myapp.elf      myapp.hex  pico-sdk
CMakeFiles      elf2uf2              Makefile   myapp.dis  myapp.uf2

The myapp.uf2 is a program which can be moved into storage of the Raspberry Pi Pico.

Upload program

Hold down the BOOTSEL button and connect the Raspberry Pi Pico to your PC via micro USB cable. Once Pico is connected, release the BOOTSEL button. This button puts Raspberry Pi Pico into USB mass storage device mode.

Find the USB mass storage device called RPI-RP2:

sudo blkid -o list | grep RPI-RP2

An example of output:

/dev/sdb1  vfat    RPI-RP2  (not mounted)  0034-04C4

Create a new directory:

sudo mkdir /mnt/pico

Mount device to /mnt/pico directory:

sudo mount /dev/sdb1 /mnt/pico

Check files in /mnt/pico:

ls /mnt/pico

If you can see the following files, then the USB mass storage device has been mounted correctly:


Copy program into storage device:

sudo cp myapp.uf2 /mnt/pico

Flush memory buffer to the storage device:

sudo sync

Raspberry Pi Pico will disconnect as a USB mass storage device and runs the code.

Note: if you want to upload new code to the Raspberry Pi Pico, disconnect it from power and hold down the BOOTSEL button when connecting Pico to power.

Test program

Program prints message to USB CDC (USB serial). So, you can open the serial port to see messages:

sudo screen /dev/ttyACM0 115200

To quit screen session, press CTRL+A and then \.

Uninstall SDK

If you decided to completely remove Raspberry Pi Pico SDK, delete the installation directory:

sudo rm -rf /opt/pico-sdk

Remove file that is used to set environment variable:

sudo rm -rf /etc/profile.d/

You can also remove build tools:

sudo apt purge --autoremove -y build-essential cpp make binutils

The 4 Comments Found

  1. Avatar
    Seamus Reply

    This was a huge help - thank you. I actually used it to install the RPi PICO SDK on Ubuntu 22.04! There were only a couple of work-arounds needed, and it's actually working now - I've just uploaded & run the helloworld app.

  2. Avatar
    tony pigram Reply

    Wonderful article - helped me to sanitise my setup.

    If I leave the ASM in the CMakeLists.txt file, I get an Error 2 failure at the end when building - however, if I remove it everything builds okay and the created u2f file runs okay on the PICO.
    I use minicom to view the output and I see a Hello world output.
    Do I need the ASM? If so, what do I need to do extra to set it up?

    • Avatar
      lindevs Reply

      In some cases, assembler is required because Raspberry Pi Pico SDK has assembler source code. I recommend reading separate post how to install Arm GNU Toolchain.
      When I run the cmake command, I get output which contains:

      PICO compiler is pico_arm_gcc
      -- The C compiler identification is GNU 12.2.1
      -- The CXX compiler identification is GNU 12.2.1
      -- The ASM compiler identification is GNU
      -- Found assembler: /opt/gcc-arm-none-eabi/bin/arm-none-eabi-gcc

      After that, I run the make command and the code compiles successfully.

  3. Avatar
    Leo Smith Reply

    I had a slew of errors for assembler instructions not being recognised.
    What had happened is that I had run cmake without the correct environment variables being set, and once that had been done the wrong assembler was baked in.

    Logging out and in didn't fix it UNTIL I DELETED EVERYTHING IN THE build directory and ran 'cmake ..' again.

    This time I got the correct assembler as mentioned in Lindevs post.

    The project then built successfully.

Leave a Comment

Cancel reply

Your email address will not be published.