Install .NET and create your first web application.
None.
10 minutes
A web app that displays a Hello, World!
message on a web page.
To start building .NET apps you just need to download and install the .NET SDK (Software Development Kit).
In order to install .NET Core from Red Hat on RHEL, you first need to register using the Red Hat Subscription Manager. If this has not been done on your system, or if you are unsure, see the Red Hat Getting Started Guide.
After registering with the Subscription Manager and enabling the .NET Core channel, you are ready to install and enable the .NET SDK.
In your command prompt, run the following commands:
yum install rh-dotnet22 -y scl enable rh-dotnet22 bash
Before installing .NET, you'll need to register the Microsoft key, register the product repository, and install required dependencies. This only needs to be done once per machine.
Open a command prompt and run the following commands:
wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb sudo dpkg -i packages-microsoft-prod.deb
Update the products available for installation, then install the .NET SDK.
In your command prompt, run the following commands:
sudo add-apt-repository universe sudo apt-get install apt-transport-https sudo apt-get update sudo apt-get install dotnet-sdk-2.2
If you receive an error message similar to Unable to locate package dotnet-sdk-2.2
, run the following command then re-attempt the install.
sudo dpkg --purge packages-microsoft-prod && sudo dpkg -i packages-microsoft-prod.deb
Before installing .NET, you'll need to register the Microsoft key, register the product repository, and install required dependencies. This only needs to be done once per machine.
Open a command prompt and run the following commands:
wget -q https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.deb sudo dpkg -i packages-microsoft-prod.deb
Update the products available for installation, then install the .NET SDK.
In your command prompt, run the following commands:
sudo apt-get install apt-transport-https sudo apt-get update sudo apt-get install dotnet-sdk-2.2
Before installing .NET, you'll need to register the Microsoft key, register the product repository, and install required dependencies. This only needs to be done once per machine.
Open a command prompt and run the following commands:
wget -q https://packages.microsoft.com/config/ubuntu/14.04/packages-microsoft-prod.deb sudo dpkg -i packages-microsoft-prod.deb
Update the products available for installation, then install the .NET SDK.
In your command prompt, run the following commands:
sudo apt-get install apt-transport-https sudo apt-get update sudo apt-get install dotnet-sdk-2.2
Before installing .NET, you'll need to register the Microsoft key, register the product repository, and install required dependencies. This only needs to be done once per machine.
Open a command prompt and run the following commands:
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.asc.gpg sudo mv microsoft.asc.gpg /etc/apt/trusted.gpg.d/ wget -q https://packages.microsoft.com/config/debian/9/prod.list sudo mv prod.list /etc/apt/sources.list.d/microsoft-prod.list sudo chown root:root /etc/apt/trusted.gpg.d/microsoft.asc.gpg sudo chown root:root /etc/apt/sources.list.d/microsoft-prod.list
Update the products available for installation, then install the .NET SDK.
In your command prompt, run the following commands:
sudo apt-get update sudo apt-get install dotnet-sdk-2.2
Before installing .NET, you'll need to register the Microsoft key, register the product repository, and install required dependencies. This only needs to be done once per machine.
Open a command prompt and run the following commands:
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc wget -q https://packages.microsoft.com/config/fedora/27/prod.repo sudo mv prod.repo /etc/yum.repos.d/microsoft-prod.repo sudo chown root:root /etc/yum.repos.d/microsoft-prod.repo
Update the products available for installation, then install the .NET SDK.
In your command prompt, run the following commands:
sudo dnf update sudo dnf install dotnet-sdk-2.2
Before installing .NET, you'll need to register the Microsoft key, register the product repository, and install required dependencies. This only needs to be done once per machine.
Open a command prompt and run the following commands:
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc wget -q https://packages.microsoft.com/config/fedora/27/prod.repo sudo mv prod.repo /etc/yum.repos.d/microsoft-prod.repo sudo chown root:root /etc/yum.repos.d/microsoft-prod.repo
Update the products available for installation, then install the .NET SDK.
In your command prompt, run the following commands:
sudo dnf update sudo dnf install dotnet-sdk-2.2
Before installing .NET, you'll need to register the Microsoft key, register the product repository, and install required dependencies. This only needs to be done once per machine.
Open a command prompt and run the following commands:
sudo rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm
Update the products available for installation, then install the .NET SDK.
In your command prompt, run the following commands:
sudo yum update sudo yum install dotnet-sdk-2.2
Before installing .NET, you'll need to register the Microsoft key, register the product repository, and install required dependencies. This only needs to be done once per machine.
Open a command prompt and run the following commands:
sudo zypper install libicu sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc wget -q https://packages.microsoft.com/config/opensuse/42.2/prod.repo sudo mv prod.repo /etc/zypp/repos.d/microsoft-prod.repo sudo chown root:root /etc/zypp/repos.d/microsoft-prod.repo
Update the products available for installation, then install the .NET SDK.
In your command prompt, run the following commands:
sudo zypper update sudo zypper install dotnet-sdk-2.2
Before installing .NET, you'll need to register the Microsoft key, register the product repository, and install required dependencies. This only needs to be done once per machine.
Open a command prompt and run the following commands:
sudo rpm -Uvh https://packages.microsoft.com/config/sles/12/packages-microsoft-prod.rpm
Update the products available for installation, then install the .NET SDK.
In your command prompt, run the following commands:
sudo zypper update sudo zypper install dotnet-sdk-2.2
Open a new command prompt and run the following commands:
dotnet new webApp -o myWebApp
cd myWebApp
dotnet new webApp -o myWebApp
cd myWebAppp
The dotnet
command creates a new
application of type webApp
for you. The -o
parameter creates a directory named myWebApp
where your app is stored, and populates it with the required files. The cd myWebApp
command puts you into the newly created app directory.
Several files were created in the myWebApp
directory, to give you a simple web application that is ready to run. Startup.cs
contains all the settings and configurations. The myWebApp/Pages
directory contains some web pages for the application.
In your command prompt, run the following command:
dotnet dev-certs https --trust
dotnet dev-certs https --trust
Your operating system may prompt to check if you agree to trust the development certificate. Follow the prompts if you agree.
This certificate allows your web app to run on HTTPS while you are developing on your machine.
In your command prompt, run the following command:
dotnet run
dotnet run
Once the command completes, browse to https://localhost:5001
Congratulations, you've built and run your first .NET web app!
Open Pages/Index.cshtml
in any text editor and add the following code above the first <div>
tag in the file:
<h1>Hello, world!</h1>
<h2>The time on the server is @DateTime.Now</h2>
Refresh the browser to see the change:
Now that you've got the basics, continue building your first ASP.NET app with Razor Pages.
You might also be interested in...