Running ASP.NET Core 9 on a Raspberry Pi Zero 2W
02/02/2025
2 minutes
This is a step by step for setting up a Raspberry Pi Zero 2W with a default ASP.NET Core 9 application (in 9 steps).
Install the Raspberry Pi Imager tool.
Install
Raspberry Pi OS Lite (64bit)
on the SD Card. Configure settings Wi-Fi/user/SSH settings during the installation.SSH into the raspberry using
ssh <user>@raspberrypi.local
orssh <ip> -l <user>
command.Install .NET runtime:
Follow documentation outlined by dotnet iot. Here I am using the Framework-Dependent approach.
curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --channel STS
Set PATH:
echo 'export DOTNET_ROOT=$HOME/.dotnet' >> ~/.bashrc
thenecho 'export PATH=$PATH:$HOME/.dotnet' >> ~/.bashrc
andsource ~/.bashrc
Run
dotnet --version
to validate that installation succeeded.
Create a folder
mkdir app
on the Raspberry Pi for the application.Publish the web application in Release, Portable, .NET 9, Framework-Dependent mode on any dev machine.
Copy the published application to the Raspberry Pi using scp:
scp -r D:\repos\..\WebApplication\bin\Release\net9.0\publish\* <user>@raspberrypi:/home/<user>/app
executed on the dev machine.To run locally the service on port 80 (443 would require a certificate), execute the following command:
sudo /home/<user>/.dotnet/dotnet /home/<user>/app/WebApplication.dll --urls http://+:80
, where sudo is required for port 80 (using port 5000 can bind without elevated privileges).Setup the application to start after boot using systemd ref:
Execute the following command to create a service and set content as
sudo nano /lib/systemd/system/webapplication.service
:
[Unit] Description=WebApplication Service After=multi-user.target [Service] Type=idle ExecStart=/home/<user>/.dotnet/dotnet /home/<user>/app/WebApplication.dll --urls http://+:80 [Install] WantedBy=multi-user.target
Set permissions
sudo chmod 644 /lib/systemd/system/webapplication.service
Reload services:
sudo systemctl daemon-reload
Enabled service
sudo systemctl enable webapplication.service
Reboot to validate setup:
sudo reboot
Open a browser on the dev machine (which is on the same network) and navigate to http://raspberrypi/