.NET Core 1.0 is here and it’s a great, great opportunity to start playing with it not only on Windows platform but also on Linux. Today I will show you not only how to run .NET Core but how to setup whole developer environment for developing .NET.
Since one of Microsoft main goals was multiplatform support, let’s take a quick look on how-to setup .NET Core on Ubuntu.
Why Ubuntu? Well.. it’s popular and easy. Also Microsoft used it as a platform of choice for their
Docker support for Windows so decision seemed quite straightforward to me. We’ll be working here on Ubuntu 14.04 LTS as it’s the most widespread version now.
You can also try other platforms as I did, especially Red Hat Enterprise which is totally free on http://developers.redhat.com/ for developers. They also fully support .NET on RHEL and are part of .NET Foundation. Quite rock-solid backed, isn’t it?
Getting .NET Core on Ubuntu
Well, that’s probably the easiest part as it well documented (for now) at Microsoft .NET Core site.
As stated in docs, execute on after another in
Terminal to install the framework:
sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet/ trusty main" > /etc/apt/sources.list.d/dotnetdev.list'
sudo apt-key adv --keyserver apt-mo.trafficmanager.net --recv-keys 417A0893
sudo apt-get -y update
sudo apt-get -y install dotnet-dev-1.0.0-preview2-003121
Let’s try if that worked. Type
dotnet in Terminal and see if command is recognized:
Alrighty. Working as intended!
Enter Yeoman – our beloved code scaffolder
Since what plain .NET Core framework offers us in terms of scaffolding is quite minimalist (we can only
dotnet new to create empty project), we must turn ourselves to other tools. One of the most popular (if not the most popular) scaffolder is Yeoman. If you’re Linux fan, you already know it very well from other projects.
In order to install Yeoman we’d need two dependencies – Node.js and npm.
Since Ubuntu 14.04 has too old version of Node.js to run Yeoman, we’d need to update it. That’s the part where I’ve struggled a little, as most of generic Ubuntu approaches I knew did not work out. I’m not Ubuntu pro so I’ve turned myself to internet and browsed for working solution.
This one seems to be always working and I’ve read that it’s generally THE recommended way of updating/installing Node.js:
sudo apt-get -y install curl
sudo curl --silent --location https://deb.nodesource.com/setup_5.x | sudo bash -
sudo apt-get -y install nodejs
If update was successful, typing node –version should return version 5.X, where X is the latest version of 5th release.
As we now have proper Node.js version, let’s proceed to Yeoman installation.
Let’s install Yeoman itself with command:
Then, we’d need generator for .NET Core templates:
sudo npm install -g generator-aspnet
If everything went smoothly, we should see Yeoman welcoming us in generator when we run yo aspnet in Terminal:
Optional step – Visual Studio Code
That might be a NO-NO solution for wide range of vim or Sublime Text fans out there, but if you’re willing to check what Microsoft has to offer in lightweight, modular code editors, give VS Code a try.
Since VS Code is generally available through http://code.visualstudio.com/ site, there is no easy way to get it through terminal.
I’ve managed to get it using
wget and downloading .deb package from Microsoft download site to Downloads folder and then installing it via
wget -O ~/Downloads/vscode-amd64.deb "https://go.microsoft.com/fwlink/?LinkID=760868"
sudo dpkg -i ~/Downloads/vscode-amd64.deb
No idea if the
?LinkID=760868 won’t change, will keep in touch with Microsoft to clarify that.
But, but… I want to automate!
Since we’re now in raging era of DevOps, we all want to automate. And that’s great! We should whenever we can.
We can easily pack all the lines above into
bash .sh file and run it with preceding
sudo to get elevated privileges.
Not enough? It’s fine as I’ve already prepare such script in my ubuntu-helpers repository on GitHub.
Just clone the repo to your Linux machine:
git clone https://github.com/m-wilczynski/ubuntu-helpers.git
Then just run bash script with:
sudo sh dotnet-install.sh
If you’re willing to contribute to ubuntu-helpers, feel free to do so on GitHub:
ubuntu-helpers @ GitHub.com