Build a Linux .NET Core Dev Machine in Under an Hour

I have a complicated relationship with Linux. Every few years, I get nostalgic about my Solaris days back in college. So I build a machine, struggle through getting all the hardware & whatnot working, and invest tons of time trying to get the Windows apps I know & love running on it. Then I give up and go back to Windows.

And that’s about where I’m at now, in the nostalgia/fascination stage with fantasies of leaving my familiar Microsoft pastures. At work, we’re moving more & more toward containerization and Kubernetes with the goal of reducing cost by hosting services on Linux. Maybe its relevance to work will give the effort more legs this time?

So I embarked on the journey (again) and have been pleased with how much the experience has matured. Doing a clean install of Ubuntu on my old laptop was completely painless. I didn’t need to do any special setup or troubleshooting to get hardware running. In fact, it was 100% as easy as installing Windows, which I was forced to do a few weeks earlier presumably due to some botched updates that had me blue-screening every few minutes.

Keeping the momentum going, I jumped right into installing .NET Core and setting up Visual Studio Code. The whole thing–from beginning to end; from formatting and installing the OS to running my first console app–took about an hour.

It was easy enough that just about anybody capable of doing a clean OS install should be able to manage it. In fact, let’s go through all the steps, right now! I’ll walk you through what’s needed from installing the OS, .NET Core, and VS Code all the way through to creating and running a new project.

Getting the operating system up & running is obviously step 1. I followed the instructions on the Ubuntu website:

  1. Create a bootable USB drive
  2. Boot off the device
  3. Follow install directions

Alternatively, you could use a virtual machine. Since I’m retracing my own steps as I write this, I’m using VirtualBox which is freely available to everybody–so no excuses about not having a spare computer laying around! If you’re going this route, download VirtualBox, fire it up, and create a new virtual machine. For reference, I picked Linux/Ubuntu (64-bit) and used all defaults*. You still need to download the Ubuntu ISO, and select it as the boot media the first time you start the VM.

*My VM kept hanging during install until I increased memory from the default 1024 MB to 2048 MB.

Alright, now we’ve got our Linux machine running, and it’s time to install .NET Core. Follow Microsoft’s instructions to install the .NET Core SDK, or open a terminal and run the following commands:

wget -q https://packages.microsoft.com/config/ubuntu/19.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
sudo apt-get update
sudo apt-get install apt-transport-https
sudo apt-get install dotnet-sdk-3.1

We’re almost there now. Install Visual Studio Code along with the C# extensions by running a couple more commands:

sudo snap install --classic code
code --install-extension ms-vscode.csharp

That’s it! Who’s ready to run some code? Use the dotnet CLI to create a new console app, open the code in VS Code, and run it using F5 or Debug > Start Debugging. (If it’s your first run with the C# extensions installed, you may need to wait while it downloads dependencies.) VS Code will ask you which environment to use; pick .NET Core to add a launch.json file which tells VS Code how to run your app.

dotnet new console -o HelloConsole
cd HelloConsole
code .

And there you have it. Reproducing the setup on a VM, I was able to download the Ubuntu ISO, create a clean install, install .NET Core SDK & runtime along with VS Code, and create & run a new C# console app in under an hour. Not bad!

Advertisement

Author: Adam Prescott

I'm enthusiastic and passionate about creating intuitive, great-looking software. I strive to find the simplest solutions to complex problems, and I embrace agile principles and test-driven development.

Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: