<亲测>centos安装 .net core 2.1

时间:2024-01-06 18:55:08

https://www.microsoft.com/net/learn/get-started-with-dotnet-tutorial#install

.NET Tutorial - Hello World in 10 minutes

Not ready to install anything? Try our in-browser tutorial.


  1. Install the .NET SDK

    To start building .NET apps you just need to download and install the .NET SDK (Software Development Kit).

    Linux Distribution

                     
    RHEL
                     
    Ubuntu 18.04
                     
    Ubuntu 17.10
                     
    Ubuntu 16.04
                     
    Ubuntu 14.04
                     
    Debian 9
                     
    Debian 8
                     
    Fedora 28
                     
    Fedora 27
                     
    CentOS / Oracle
                     
    openSUSE
                     
    SLES
         

    Add the dotnet product feed

    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
    

    Install the .NET SDK

    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.1
  2. Create your app

    Open a new command prompt and run the following commands:

    dotnet new console -o myApp
    cd myApp

    The dotnet command creates a new application of type console for you. The -o parameter creates a directory named myAppwhere your app is stored, and populates it with the required files. The cd myApp command puts you into the newly created app directory.

    The main file in the myApp folder is Program.cs. By default, it already contains the necessary code to write "Hello World!" to the Console.

    using System;
    
    namespace myApp
    {
    class Program
    {
    static void Main(string[] args)
    {
    Console.WriteLine("Hello World!");
    }
    }
    }
  3. Run your app

    In your command prompt, run the following command:

    dotnet run

    Congratulations, you've built and run your first .NET app!

  4. Get an editor

    Visual Studio Code is a free, cross-platform code editor with support for .NET.

    Download Visual Studio Code

    For full language support including smart code completion and debugging, get the C# extension for Visual Studio Code.

    Download the C# Extension

  5. Keep learning

    Now that you've got the basics, you can keep learning with the .NET Quick Starts. In the first Quick Start you'll learn about collections.

    Quick start: Collections