In this recipe, we will learn how to install the .NET Core components in order to create an ASP.NET Core MVC application on macOS.
Because macOS is based on Unix, it is possible to run a .NET application on it with the Mono
project. As mentioned in the previous recipe, for the moment, .NET application needs Mono
to run on Linux or macOS.
To install Mono
, we use Homebrew
(http://brew.sh/), which is a package manager for macOS.
In this recipe, we will do the following:
- Install
Homebrew
by entering this command at a Terminal:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- Use
Homebrew
to getDNVM
,DNX
, andDNU
using the commands as follows:
$ brew tap aspnet/dnx
$ brew update
$ brew install dnvm
$ source dnvm.sh
- Install Node.js and npm (the npm will be installed automatically with Node.js):
$ brew install node
- Verify Node.js and NPM versions:
$ node -v
$ npm -v
The version currently being used will be displayed on your screen as follows:
- Install
Yeoman
withGulp
to help automate tasks:
$ npm install -g yo gulp
$ npm install -g generator-aspnet
Yeoman
asks us what type of application we want to create. In our case, we choose Web Application Basic.- After that,
Yeoman
asks us the name for the application to create, as shown in the following screenshot. Yeoman
will generate all the necessary files to run an ASP.NET Core MVC application. After the project is created,Yeoman
shows us the different commands we can use to run the application.- With the command
cd "nameoftheapplication"
, we are placed in the application directory.
- After that, we can run the
dotnet restore
command, which will restore all the dependencies needed to run the application. In the background, this command will connect to theNuGet
online repository to download, asNuGet
packages the missing dependencies:
$ dotnet run
After executing the preceding command you get the following output at localhost:5000
: