|
1 | 1 | .. include:: /stub-topic.txt |
2 | 2 |
|
3 | | -|stub-icon| Installing .NET Core on Linux |
| 3 | +Installing .NET Core on Linux |
4 | 4 | ========================================= |
5 | 5 |
|
6 | | -.. include:: /stub-notice.txt |
7 | | - |
| 6 | +These instructions will lead you through acquiring the .NET Core DNX SDK |
| 7 | +via the `.NET Version Manager (DNVM) <https://github.com/aspnet/dnvm>`__ |
| 8 | +and running a "Hello World" demo on Linux. |
| 9 | + |
| 10 | +.NET Core NuGet packages and the .NET Core DNX SDKs are available on the |
| 11 | +`ASP.NET 'vnext' myget feed <https://www.myget.org/F/aspnetvnext>`__, |
| 12 | +which you can more easily view on |
| 13 | +`gallery <https://www.myget.org/gallery/aspnetvnext>`__ for the feed. |
| 14 | + |
| 15 | +Setting up the environment |
| 16 | +-------------------------- |
| 17 | + |
| 18 | +These instructions have been written and tested on Ubuntu 14.04 LTS, since that is the main Linux distribution the .NET Core team uses. These instructions may succeed on other distributions as well. We are always accepting new pull requests on `our GitHub repo <https://www.github.com/dotnet/coreclr/>`_ that address running on other Linux distributions. The only requirement is that they do not break the ability to use Ubuntu 14.04 LTS. |
| 19 | + |
| 20 | +Installing the required packages |
| 21 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 22 | + |
| 23 | +Install the ``libunwind8``, ``libssl-dev`` and ``unzip`` packages: |
| 24 | + |
| 25 | +:: |
| 26 | + |
| 27 | + sudo apt-get install libunwind8 libssl-dev unzip |
| 28 | + |
| 29 | +You also need a latest version of Mono, which is required for DNX tooling. This is a temporary requirement, and will not be required in the future. |
| 30 | + |
| 31 | +:: |
| 32 | + |
| 33 | + sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF |
| 34 | + echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list |
| 35 | + sudo apt-get update |
| 36 | + sudo apt-get install mono-complete |
| 37 | + |
| 38 | +Certificates |
| 39 | +^^^^^^^^^^^^ |
| 40 | + |
| 41 | +You need to import trusted root certificates in order to restore NuGet packages. You can do that with the ``mozroots`` tool. |
| 42 | + |
| 43 | +:: |
| 44 | + |
| 45 | + mozroots --import --sync |
| 46 | + |
| 47 | +Installing DNVM |
| 48 | +--------------- |
| 49 | + |
| 50 | +You need DNVM as a starting point. DNVM enables you to acquire one or multiple .NET Execution Environments (DNX). DNVM is a shell script and does not require .NET. You can use the below command to install it. |
| 51 | + |
| 52 | +:: |
| 53 | + |
| 54 | + curl -sSL https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.sh | DNX_BRANCH=dev sh && source ~/.dnx/dnvm/dnvm.sh |
| 55 | + |
| 56 | +Installing the .NET Core DNX |
| 57 | +---------------------------- |
| 58 | + |
| 59 | +You first need to acquire the Mono DNX. It doesn't include Mono, but is |
| 60 | +needed to use the DNX tools on top of Mono. In particular, the DNU |
| 61 | +command is not yet supported on .NET Core, requiring us to use Mono for |
| 62 | +this purpose (until DNU runs on .NET Core). Mono is the default DNX, so |
| 63 | +you can acquire it via ``dnvnm upgrade``. |
| 64 | + |
| 65 | +:: |
| 66 | + |
| 67 | + dnvm upgrade -u |
| 68 | + |
| 69 | +Next, acquire the .NET Core DNX SDK. |
| 70 | + |
| 71 | +:: |
| 72 | + |
| 73 | + dnvm install latest -r coreclr -u |
| 74 | + |
| 75 | +You can see the currently installed DNX versions with ``dnvm list``. |
| 76 | + |
| 77 | +:: |
| 78 | + |
| 79 | + dnvm list |
| 80 | + |
| 81 | +:: |
| 82 | + |
| 83 | + Active Version Runtime Arch Location Alias |
| 84 | + ------ ------- ------- ---- -------- ----- |
| 85 | + * 1.0.0-beta5-11649 coreclr x64 ~/.dnx/runtimes |
| 86 | + 1.0.0-beta5-11649 mono ~/.dnx/runtimes default |
| 87 | + |
| 88 | +Using a specific runtime |
| 89 | +------------------------ |
| 90 | + |
| 91 | +You can choose which of the installed DNXs you want to use with ``dnvm use``, specifying arguments that are similar to the ones used when installing a runtime. |
| 92 | + |
| 93 | +:: |
| 94 | + |
| 95 | + dnvm use -r coreclr -arch x86 1.0.0-beta5-11649 |
| 96 | + Adding ~/.dnx/runtimes/dnx-coreclr-win-x86.1.0.0-beta5-11649/bin |
| 97 | + to process PATH |
| 98 | + |
| 99 | + dnvm list |
| 100 | + |
| 101 | + Active Version Runtime Arch Location Alias |
| 102 | + ------ ------- ------- ---- -------- ----- |
| 103 | + * 1.0.0-beta5-11649 coreclr x64 ~/.dnx/runtimes |
| 104 | + 1.0.0-beta5-11649 mono ~/.dnx/runtimes default |
| 105 | + |
| 106 | +See the asterisk in the listing above? It's purpose is to tell you which runtime is now active. "Active" here means that all of the interaction with your projects and .NET Core will use this runtime. |
| 107 | + |
| 108 | +That's it! You now have the .NET Core runtime installed on your machine and it is time to take it for a spin. |
| 109 | + |
| 110 | +Write your App |
| 111 | +-------------- |
| 112 | + |
| 113 | +his being an introduction-level document, it seems fitting to start with a "Hello World" app. Here's a very simple one you can copy and paste into a CS file in a directory. |
| 114 | + |
| 115 | +.. code:: csharp |
| 116 | +
|
| 117 | + using System; |
| 118 | +
|
| 119 | + public class Program |
| 120 | + { |
| 121 | + public static void Main (string[] args) |
| 122 | + { |
| 123 | + Console.WriteLine("Hello, Linux"); |
| 124 | + Console.WriteLine("Love from CoreCLR."); |
| 125 | + } |
| 126 | + } |
| 127 | +
|
| 128 | +A more ambitious example is available on the `corefxlab repo <https://www.github.com/dotnet/corefxlab/>`_ that will print out a pretty picture based on the argument you provide at runtime. If you wish to use this example, simply save the `C# file <https://raw.githubusercontent.com/dotnet/corefxlab/master/demos/CoreClrConsoleApplications/HelloWorld/HelloWorld.cs>`_ to a directory somewhere on your machine. |
| 129 | + |
| 130 | +The next thing you will need is a ``project.json`` file that will outline the dependencies of an app, so you can **actually** run it. Use the contents below, it will work for both examples above. Save this file in a directory next to the CS file that contains your code. |
| 131 | + |
| 132 | +:: |
| 133 | + |
| 134 | + { |
| 135 | + "version": "1.0.0-*", |
| 136 | + "dependencies": { |
| 137 | + }, |
| 138 | + "frameworks" : { |
| 139 | + "dnx451" : { }, |
| 140 | + "dnxcore50" : { |
| 141 | + "dependencies": { |
| 142 | + "System.Console": "4.0.0-beta-*" |
| 143 | + } |
| 144 | + } |
| 145 | + } |
| 146 | + } |
| 147 | + |
| 148 | +Run your App |
| 149 | +------------ |
| 150 | + |
| 151 | +You need to restore packages for your app, based on your project.json, |
| 152 | +with ``dnu restore``. You will need to run this command under the Mono |
| 153 | +DNX. The first command switches the active runtime to the Mono one. |
| 154 | + |
| 155 | +:: |
| 156 | + |
| 157 | + dnvm use 1.0.0-beta5-11649 -r mono |
| 158 | + dnu restore |
| 159 | + |
| 160 | +You are now ready to run your app under .NET Core. As you can guess, however, before you do that you first need to switch to the .NET Core runtime. The first command below does exactly that. |
| 161 | + |
| 162 | +:: |
| 163 | + |
| 164 | + dnvm use 1.0.0-beta5-11649 -r coreclr |
| 165 | + dnx . run |
| 166 | + |
| 167 | + Hello, Linux |
| 168 | + Love from CoreCLR. |
| 169 | + |
| 170 | +Building .NET Core from source |
| 171 | +------------------------------ |
| 172 | +.NET Core is an open source project that is hosted on GitHub. This means that you can, at any given time, clone the repository and build .NET Core from source. This is a more advanced scenario that is usually used when you want to add features to the .NET runtime or the BCL or if you are a contributor to these projects. The detailed instruction on how to build .NET Core windows can be found in the `.NET Core OS X build instructions <https://github.com/dotnet/coreclr/blob/master/Documentation/linux-instructions.md>`_ on GitHub. |
0 commit comments