.NET is a popular platform for building and running applications and services on Windows and other operating systems. With the release of .NET 7, you can now take advantage of the latest features and improvements in the .NET platform to build modern applications. To install dotnet 7 on Ubuntu, you can follow these steps:
Remove existing dotnet sdk
sudo snap remove dotnet-sdk
Install the Microsoft package repository
Run these commands to install the Microsoft package repository on Ubuntu:
wget https://packages.microsoft.com/config/debian/11/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb
The first command uses wget to download the file from the specified URL and save it to a file named packages-microsoft-prod.deb on your Ubuntu system. The -O option specifies an output file name. The second command installs the downloaded configuration file using dpkg, which requires administrative privileges because this install requires elevated permissions. The -i option tells dpkg to install the specified package file.
Install dotnet 7 sdk
Install the dotnet sdk by running these commands:
sudo apt-get update && \
sudo apt-get install -y dotnet-sdk-7.0
To install the .NET Core SDK on an Ubuntu system, run two commands: sudo apt-get update and sudo apt-get install -y dotnet-sdk-7.0. The first command updates the package list on your computer, downloading information about the latest versions of packages and their dependencies from repositories defined in your system’s package sources. The -y option automatically confirms the installation of packages without prompting for confirmation.
Output of the above command will be like this:
Hit:1 http://us-east-1.ec2.archive.ubuntu.com/ubuntu jammy InRelease
Hit:2 http://us-east-1.ec2.archive.ubuntu.com/ubuntu jammy-updates InRelease
Hit:3 http://us-east-1.ec2.archive.ubuntu.com/ubuntu jammy-backports InRelease
Hit:4 https://packages.microsoft.com/ubuntu/22.04/prod jammy InRelease
Hit:5 http://security.ubuntu.com/ubuntu jammy-security InRelease
Reading package lists… Done
Reading package lists… Done
Building dependency tree… Done
Reading state information… Done
Run the following command to get the info for the dotnet installation:
dotnet --info
output:
.NET SDK:
Version: 7.0.200
Commit: 534117727b
Runtime Environment:
OS Name: ubuntu
OS Version: 22.04
OS Platform: Linux
RID: ubuntu.22.04-x64
Base Path: /usr/share/dotnet/sdk/7.0.200/
Host:
Version: 7.0.3
Architecture: x64
Commit: 0a2bda10e8
.NET SDKs installed:
7.0.200 [/usr/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 7.0.3 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 7.0.3 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Other architectures found:
None
Environment variables:
Not set
global.json file:
/home/ubuntu/actions-runner/_work/kokotree-learn/kokotree-learn/global.json
Learn more:
https://aka.ms/dotnet/info
Download .NET:
Install dotnet runtime to install dotnet 7 on Ubuntu
Run the following commands to install dotnet 7 on Ubuntu:
sudo apt-get update && \
sudo apt-get install -y aspnetcore-runtime-7.0
The first command, sudo apt-get update, updates the package list on the system. This command retrieves information about the latest versions of packages and their dependencies from the package repositories defined in the system’s package sources. The second command, sudo apt-get install -y aspnetcore-runtime-7.0, installs .NET Core runtime version 7.0 on your system. The -y option automatically confirms the installation of the package and its dependencies without prompting for confirmation.
The output of the above command will be like this:
Hit:1 http://us-east-1.ec2.archive.ubuntu.com/ubuntu jammy InRelease
Hit:2 http://us-east-1.ec2.archive.ubuntu.com/ubuntu jammy-updates InRelease
Hit:3 http://us-east-1.ec2.archive.ubuntu.com/ubuntu jammy-backports InRelease
Hit:4 https://packages.microsoft.com/ubuntu/22.04/prod jammy InRelease
Hit:5 http://security.ubuntu.com/ubuntu jammy-security InRelease
Reading package lists… Done
Reading package lists… Done
Building dependency tree… Done
Reading state information… Done
aspnetcore-runtime-7.0 is already the newest version (7.0.2-1).
aspnetcore-runtime-7.0 set to manually installed.
The following packages were automatically installed and are no longer required:
aspnetcore-targeting-pack-6.0 dotnet-apphost-pack-6.0 dotnet-hostfxr-6.0 dotnet-runtime-deps-6.0 dotnet-targeting-pack-6.0 dotnet-templates-6.0 libflashrom1 libftdi1-2
liblttng-ust-common1 liblttng-ust-ctl5 liblttng-ust1
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 21 not upgraded.
dotnet –list-sdks
Output:
7.0.200 [/usr/share/dotnet/sdk]
dotnet –list-runtimes
Output:
Microsoft.AspNetCore.App 7.0.3 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 7.0.3 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Verify the installation
dotnet --list-sdks
The output of the dotnet –list-sdks command should be like this:
7.0.102 [/usr/share/dotnet/sdk]
The dotnet –list-sdks command displays a list of all the .NET Core SDKs that are installed on your system, including their version numbers, installation paths, and other useful information. This command can be used by developers who need to know which versions of the SDK are available for use on their systems.
Run the dotnet --list-runtimes
command to get the information on runtimes installed.
dotnet --list-runtimes
Output:
Microsoft.AspNetCore.App 7.0.3 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 7.0.3 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
The “dotnet –list-runtimes” command provides a list of all the .NET runtime environments installed on your system, with each runtime corresponding to a specific version of the .NET framework. When you run this command, it displays information for each installed runtime, including its version number, name, identifier, and type. The name typically includes the operating system and architecture it is built for, and the identifier is a unique value that can be used in other commands. The type of runtime can either be an SDK or a Runtime.
The steps mentioned above to install dotnet 7 on Ubuntu will help you get started developing .NET 7 applications on Ubuntu, and take advantage of the latest features and improvements in the .NET platform.