This entry has been updated and republished to account for the breaking changes which have taken place in the vNext (now DNVM) project
.NET has gone open source!
It''s now possible to build and run .NET applications on OSX and Linux. To install and run ASP vNext on a Digital Ocean Ubuntu droplet is relatively straightforward.
Step 1 - Get Mono
Although .NET is coming to OSX and Linux, until an offical release of the .NET CLR, Mono is still the way to go.
Mono can either be installed by downloading and compiling the latest release, or you can use the packaged version. Use the packages directly from the Mono Project to ensure they are the latest versions.
Full installation instructions can be found here (including for Fedora and other RPM based distributions) but in summary:
The following steps are easiest in a root shell, root is usually disabled in Ubuntu but can be accessed using
sudo as below
sudo su -
Add the Mono Project GPG signing key with:
apt-key adv --keyserver pgp.mit.edu --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
Next, add the package repository:
echo "deb http://download.mono-project.com/repo/debian wheezy main" > /etc/apt/sources.list.d/mono-xamarin.list
Note that although the package was built against Debian Wheezy, it will work in a number of derivatives including Ubuntu
If you plan to develop web applications, you will also need to add a second repository to install mod_mono to provide support in Apache. The repository you need is determined by the version of Ubuntu you have installed.
lsb_release -r to check the installed version and if the version if 13.10 (Debian 8.0) or later you will need to add the repository
echo "deb http://download.mono-project.com/repo/debian wheezy-apache24-compat main" >> /etc/apt/sources.list.d/mono-xamarin.list
For earlier version including 12.04 and 12.10, you will need to instead run
echo "deb http://download.mono-project.com/repo/debian wheezy-libtiff-compat main" >> /etc/apt/sources.list.d/mono-xamarin.list
After these steps, run the following to update your system and install mono:
apt-get update apt-get upgrade apt-get install mono-complete
To build libuv you should do the following:
sudo apt-get install automake curl libtool curl -sSL https://github.com/libuv/libuv/archive/v1.4.2.tar.gz | sudo tar zxfv - -C /usr/local/src cd /usr/local/src/libuv-1.4.2 sudo sh autogen.sh sudo ./configure sudo make sudo make install sudo rm -rf /usr/local/src/libuv-1.4.2 && cd ~/ sudo ldconfig
make install puts
/usr/local/lib, in the above commands
ldconfig is used to update
ld.so.cache so that
man dlopen) can load it. If you are getting libuv some other way or not running
make install then you need to ensure that dlopen is capable of loading
Now let''s get DNVM. To do this run:
sudo apt-get install unzip curl -sSL https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.sh | DNX_BRANCH=dev sh && source ~/.dnx/dnvm/dnvm.sh
Once this step is complete you should be able to run
dnvm and see some help text.
Add Sources to NuGet.config
Now that we have DNVM and the other tools needed to run an ASP.NET application we need to add the development configuration sources to get nightly builds of all the ASP.NET packages.
The nightly package source is:
To add this to your package sources you need to edit the NuGet.config.
The NuGet.config file should look something like the following:
<?xml version="1.0" encoding="utf-8"?> <configuration> <packageSources> <add key="AspNetVNext" value="https://www.myget.org/F/aspnetvnext/api/v2/" /> <add key="nuget.org" value="https://www.nuget.org/api/v2/" /> </packageSources> <disabledPackageSources /> </configuration>
The important part of this is that you have a package source with aspnetvnext and nuget.org in it.
Install SSL certs
At this point, there is one final step that must be taken (Credit to Thinktecture for this find)
ASP.NET vNext uses NuGet packages which are signed. In Windows, .NET uses the Windows Certificate Store to determine whether to accept an SSL certificate. Mono has it''s own certificate store which is empty by default so we need to add entries as below
sudo certmgr -ssl -m https://go.microsoft.com sudo certmgr -ssl -m https://nugetgallery.blob.core.windows.net sudo certmgr -ssl -m https://nuget.org sudo certmgr -ssl -m https://www.myget.org/F/aspnetvnext/ mozroots --import --sync
Step 2 - Running an application in ASP.NET vNext
Now that you have DNVM, you need to use it to download a DNX (.NET Execution Environment) to run your applications with:
DNVM has the concept of a stable and unstable feed. Stable defaults to NuGet.org while unstable defaults to our dev MyGet feed. So if you add
-unstableto any of the install or upgrade commands you will get our latest CI build of the DNX instead of the one last released on NuGet.
DNVM works by manipulating your path. When you install a runtime it downloads it and adds the path to the dnx binary to your
PATH. After doing upgrade you should be able to run
dnvm list and see an active runtime in the list.
You should also be able to run
dnx and see the help text of the
To test everything is working, get the samples provided by the ASP.NET team
git clone https://github.com/aspnet/home
Navigate to the HelloMvc sample and run
dnu restore to build the project and to launch the sample, simply run
(A web application on Windows can use
dnx web instead. To run a console application simply run
dnx run instead)
The kestrel web server will default to port 5004 so simply navigate to http://localhost:5004 to see ASP.NET running on Linux!
In the below screenshot I added the following line to show the Operating System
<h1>Running on @Environment.OSVersion.Platform</h1>
Step 3 - Starting new projects
To start projects, there is a yeoman generator that can build console, web and MVC applications.
The project homepage is https://www.npmjs.org/package/generator-aspnet
To install (presuming you don''t already have npm installed)
sudo apt-get install npm npm install -g generator-aspnet
Have fun developing in .NET on Linux
Edit (1 April 2015)
To access an application through port 80, a simple and safe solution is to proxy it through nginx.
See here for more details!