Install. NET Core R2 on CentOS 7 and run Hello World

Source: Internet
Author: User
Tags dotnet

Install. NET Core R2 on CentOS 7 and run Hello World
Preface

Last month, the latest version of. NET Core was available, but it was tested on the Window system. I originally wanted to try it on the Linux system when I was releasing the official version. It may take some time, but I can try it if I have time.

Because the previously installed Ubuntu system is 16.04, which is not currently supported, it has not been tested on Ubuntu.

System Environment: CentOS 7 (1511) Minimal Core version.

Install

Tip:
Nodejs and Yeoman are used to automatically create ASP. NET projects. They are not mandatory.
This article is an ASP. NET project created with Yeoman, so Nodejs and Yeoman installation are added.
If you do not need it, do not install it.

. NET Core [required]

1. Download. NET Core: dotnet-dev-centos-x64.1.0.0-preview1-002702.tar.gz.

2. Move and decompress the downloaded Installation File.

$ # Create a dotnet folder $ mkdir ~ /Dotnet $ # copy the dotnet installation file to the dotnet folder $ cp dotnet-dev-centos-x64.1.0.0-preview1-002702.tar.gz ~ /Dotnet $ # decompress the Installation File $ tar-xzf ~ /Dotnet/dotnet-dev-centos-x64.1.0.0-preview1-002702.tar.gz $ # Delete the original file under the dotnet folder $ rm ~ // Dotnet/dotnet-dev-centos-x64.1.0.0-preview1-002702.tar.gz

3. Add a soft connection for global use.

$ ln -s ~/dotnet/dotnet /usr/local/bin

4. test whether the installation is successful.

$ Dotnet -- version1.0.0-preview1-002702 # output version number
Nodejs [Optional]

Do not use the built-in installation. The version is too low.

1. Go to the official website to download nodejs Installation File: node-v4.4.5-linux-x64.tar.xz.

2. Copy and decompress the package.

$ # Create a nodejs folder $ mkdir/usr/local/nodejs $ # copy the node installation file to the nodejs folder $ cp node-v4.4.5-linux-x64.tar.xz/usr/local/nodejs $ # unzip the Installation File $ tar- zvxf/usr/local/nodejs/node-v4.4.5-linux-x64.tar.xz $ # Delete the original file under the nodejs folder $ rm/usr/local/nodejs/node-v4.4.5-linux-x64.tar.xz

3. Add a soft connection for global use.

$ sudo ln -s /usr/local/nodejs/node /usr/local/bin/node$ sudo ln -s /usr/local/nodejs/npm /usr/local/bin/npm$ sudo ln -s /usr/local/nodejs/node /usr/bin/node$ sudo ln -s /usr/local/nodejs/node /usr/lib/node$ sudo ln -s /usr/local/nodejs/npm /usr/bin/npm

4. test whether the installation is successful.

$ Node-vv4.4.5 # output version number $ npm-v3.9.5 # output version number
Yeoman [Optional]

Yeoman is used to create asp.net, and relevant node plug-ins must be installed: bower, grunt, and gulp.

1. Run the installation command using npm

$ sudo npm install -g yo bower grunt-cli gulp

Wait until the installation is complete.

2. Install the asp.net generator.

$ npm install -g generator-aspnet

3. Add System Variables

Add the bin folder of node to system variables. Otherwise, the npm agent command does not exist.

Open the. bashrc file in the user directory:

$ vi ~/.bashrc

Add the following content at the end:

export PATH="/usr/local/nodejs/bin":$PATH

Use the "source" command to make it effective:

$ source ~/.bashrc
VSCode [Optional]

This may not be installed, if you do not need to modify the code.

1. Go to the official website to download the installation package: vscode-x86_64.rpm

2. Perform Installation

$ rpm -ivh vscode-x86_64.rpm

3. test whether the installation is successful.

$ code

If vscode can be started, the installation is correct.

Note: If you use a zip file for installation, the steps are the same as those of. NET Core. You also need to install unzip

C # extension needs to be installed. In vscode, press the shortcut keyCtrl + Shift + P, Enter the following command:

ext install csharp
Create a console Program

The steps are directly written in the code.

$ # Create a folder $ mkdir ~ /Dotnetcore $ mkdir ~ /Dotnetcore/leleapp $ cd ~ /Dotnetcore/ConsoleApp $ # create a console program $ dotnet new $ # restore the nuget package $ dotnet restore $ # compile $ dotnet build $ # run $ dotnet run

Actual operation diagram (example ):

Create an ASP. NET Program

This article uses Yeoman scaffolding to create.

1. Execute the commandyo aspnet:

Select the third item, Web Application.

2. Select the UI framework. Bootstrap is selected here:

3. Enter the project name. The default value is:

4. Wait until installation is complete

5. Execute the commands in sequence as prompted.

$ Cd WebApplication $ # restore the nuget package $ dotnet restore $ # compile $ dotnet build $ # create an SQLite database $ dotnet ef database update $ # run $ dotnet run

6. view results

Run the asp.net core program using the self-compiled coreclr and donet cli in Linux.

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.