Here is how to install and set up Microsoft’s .Net Core 5 on Raspberry Pi, this tutorial covers installation for both 64 and 32-bit ARM architecture.
I am using Ubuntu 20.04, but Raspbian should work as well.
To check what OS architecture the Raspberry Pi is, run the following command.
uname -m
The output should be something like this. The example below shows an output of ARM 64 architecture.
aarch64
The reason we are doing this test is so we could download the appropriate build archive of .Net Core 5.
Downloading the wrong architecture will not run on the Pi. It will throw an error that states “dotnet file or folder not found”.
Downloads for ARM 64.
The .NET SDK 5.0.101.
wget https://download.visualstudio.microsoft.com/download/pr/2add7523-39ec-413a-b8a7-24361cc4e599/30489ebd7ebcc723da48a64669860fd0/dotnet-sdk-5.0.101-linux-arm64.tar.gz
Code language: JavaScript (javascript)
The ASP.NET Core Runtime 5.0.1
wget https://download.visualstudio.microsoft.com/download/pr/e12f9b23-cb47-4718-9903-8a000f85a442/d1a6a6c75cc832ad8187f5bce0d6234a/aspnetcore-runtime-5.0.1-linux-arm64.tar.gz
Code language: JavaScript (javascript)
Downloads for ARM 32.
The .NET SDK 5.0.101.
wget https://download.visualstudio.microsoft.com/download/pr/567a64a8-810b-4c3f-85e3-bc9f9e06311b/02664afe4f3992a4d558ed066d906745/dotnet-sdk-5.0.101-linux-arm.tar.gz
Code language: JavaScript (javascript)
The ASP.NET Core Runtime 5.0.1
wget https://download.visualstudio.microsoft.com/download/pr/11977d43-d937-4fdb-a1fb-a20d56f1877d/73aa09b745586ac657110fd8b11c0275/aspnetcore-runtime-5.0.1-linux-arm.tar.gz
Code language: JavaScript (javascript)
Creating the required directory and extracting these archives into the folder.
This folder is created as a hidden type because we don’t need to have the folders listed or shown in the file manager, this is the location where the executables and libraries .Net
are stored. If you want to change the location, feel free to do the required changes.
mkdir ~/.dotnet/
Code language: JavaScript (javascript)
Extracting the archives to the .dotnet
folder.
tar -xvf dotnet-sdk-5.0.101-linux-arm64.tar.gz -C ~/.dotnet
tar -xvf aspnetcore-runtime-5.0.1-linux-arm64.tar.gz -C ~/.dotnet
Setting up dotnet to work with bash.
Open the .bashrc
file and add the following lines below, for this we are using nano
, but you can use any editor of your choice.
nano ~/.bashrc
Add the lines below to the end of the .bashrc
file.
export DOTNET_ROOT=$HOME/.dotnet
export PATH=$PATH:$HOME/.dotnet
Code language: PHP (php)
Save the file, by pressing Control
+ X
+ Y
.
You can close this terminal session or SSH connection when you re-login you will have dotnet
working.
If you want to continue with the same ssh or terminal session run this command and follow the other steps listed below.
source ~/.bashrc
Testing to see if it works correctly.
Let’s check the dotnet
version.
dotnet --version
The output should be something similar to the one below.
ubuntu@pi:~$ dotnet --version
5.0.101
Let’s create our first dotnet project. This command will create a console application with the folder and project name myApp.
dotnet new console -o myApp
Code language: JavaScript (javascript)
Compiling the application and running it.
cd myApp
dotnet build
The output should be something similar to this.
ubuntu@pi:~/projects/myApp$ dotnet build
Microsoft (R) Build Engine version 16.8.0+126527ff1 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
All projects are up-to-date for restore.
myApp -> /home/ubuntu/projects/myApp/bin/Debug/net5.0/myApp.dll
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:20.41
Code language: JavaScript (javascript)
Now let’s run the app.
dotnet run
The output will be like the one below.
ubuntu@pi:~/projects/myApp$ dotnet run
Hello World!
Code language: JavaScript (javascript)
If you want to have a complete development environment with an IDE-like interface like Microsoft’s Visual Studio Code. Follow the guidelines listed below to set up Code-Server on Raspberry Pi.
Thank you for taking the time to read this article, have a great new year.