I know, I know, most of us wave the Windows flag. But, being developers, many of us hold a special place for Linux, as our college years were spent in the vacuum of free and open source software.

One of my professors would not let any of our work be done on or assisted by proprietary software.

For me, Linux speaks to my minimalist side. Something about it feels…clean. The bare essentials of an operating system.

For years I’ve gone off and on with having a dual-boot of one distro or another, usually something lightweight and based on Debian.

Currently I’m dual-booting Elementary OS, a Mac OS-esque flavor of Ubuntu 14.04 that runs smooth as butter and is where I generate this blog using Jekyll.

Because we have been blessed with a cross-platform version of dotnet, and after seeing a few requests for C# environment setup guides, I’m going to…do just that: Install a C# development environment on Linux.

If you have ever used Linux, you might recall that sometimes things can get quite hairy. Fortunately for us, this went almost perfectly besides one or two glitches here and there.

This guide will be best suited for those like me who are slightly better than complete beginners on Linux.

Let’s get to it!

My system:

elementary OS 0.3.2 Freya (64-bit - Built on Ubuntu 14.04)

If you aren’t using elementary or any other version of Linux based on Ubuntu 14.04, you’ll want to make sure you pick the install and download options for your system.

Our first step is to install the .NET Core SDK (software development kit). This contains the .NET Core Runtime for running apps and the command line tools for creating them.

You can and should follow this beautifully done guide from Microsoft to get it installed and I’ll just cover any hiccups along the way. You may decide to ditch me at this point depending on how gung-ho you are, and all the fire to you!

Adding the dotnet apt-get feed

It’s all command-line from here, folks. These first set of commands will give you access to the SDK files.

I copied and pasted all three of the commands meant for Ubuntu 14.04 into the default terminal app in Elementary OS (called pantheon, apparently). You’ll have to put in your password to run them after you hit enter.

Here they are again, just in case:

sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet-release/ yakkety main" > /etc/apt/sources.list.d/dotnetdev.list'

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 417A0893

sudo apt-get update

No issues there, let’s keep going!

Installing the .NET Core SDK

Now that we have access to the SDK files with apt-get, we have to… apt-get them.

Running the below command also went without a hitch!

sudo apt-get install dotnet-dev-1.0.0-preview2.1-003177

The specific command could change, so be sure to use what the guide from Microsoft shows.

Once that’s done installing, you are actually all set to start writing code with C#.

If you’ve already got a favorite editor, you can follow the remaining steps of the Microsoft guide and open the generated Program.cs file to get started.

Maybe you’re one of those crazy VIM or emacs users… I never gave it enough of a shot.

If you’d rather use something built specifically for C#, Visual Studio Code is the de facto standard.

Installing Visual Studio Code

To install, I visited this URL and chose the .deb version since that will install with the Ubuntu Software Center.

Open the download with Software Center and hit the install button.

After some time, you’ll be asked for your password and it may look like the install has stopped because the install button will reappear, but just look on the Progress tab to see the true progress.

Once installed, open it for the first time.

I won’t get into the nitty gritty of VS Code, there are plenty of great guides out there, but I’ll point out the one issue I had that you might run into:

If you press CTRL+`, it will open a terminal window, but for some reason it would not display the text I was typing.

It fixed itself after I tried changing the default terminal by going to File -> Preferences -> Workspace Settings and overwriting the default shell to use pantheon.

{
    "terminal.integrated.shell.linux": "/bin/bash"
}

Pantheon didn’t work, so I put it back to /bin/bash and restarted the app. I’m not sure if it was the change I made or simply restarting it that fixed it…

Extensions

VS Code has a ton of great extensions for things like code-highlighting and intellisense. You can go to View -> Extensions to search the marketplace, but many of them will auto-suggest depending on the context.

If you open a C# project, it will suggest you download the C# extension that will add highlighting and some other features to the editor.

Knock your socks off.

What next?

We now have the tools you need to begin writing C# applications on Linux.

We’ll write the code in an editor like VS Code, and then use the terminal to compile and run it using dotnet run.