Outsourced IT Partner
Support · systems · strategyOne person, one business — IT support here, websites at webology.online.
C# on Ubuntu Linux: A Comprehensive 7-Day Guide
Setup, installation, and learning path for C# development in Linux environments
Beginner Friendly
C# has evolved from a Windows-centric language to a truly cross-platform powerhouse. With the advent of .NET Core and its evolution into the unified .NET platform, C# development on Linux has become not just possible, but a first-class experience. This comprehensive guide will take you through setting up a C# development environment on Linux and guide you through a 7-day learning journey to become proficient in C# development.
Table of Contents
- Introduction to C# and .NET on Linux
- Day 1: Environment Setup and First Steps
- Day 2: C# Fundamentals
- Day 3: Object-Oriented Programming
- Day 4: Advanced C# Features and Data Handling
- Day 5: Building a Console Application
- Day 6: Web Development with ASP.NET Core
- Day 7: Deployment and Advanced Topics
- Resources and References
Introduction to C# and .NET on Linux
C# (pronounced "C-sharp") is a modern, object-oriented programming language developed by Microsoft. Initially released in 2000 as part of the .NET Framework, C# was primarily a Windows-centric language. However, with the introduction of .NET Core in 2016 and its evolution into the unified .NET platform, C# has become a truly cross-platform language that runs excellently on Linux.
By 2025, we're working with .NET 10, which represents a significant evolution in the platform's capabilities, particularly for Linux development. The modern .NET is:
- Open Source: The entire .NET platform is open source, with active community contributions.
- Cross-Platform: Runs on Windows, Linux, macOS, and more.
- High-Performance: Offers excellent performance, often comparable to or better than other compiled languages.
- Modern: Supports the latest programming paradigms and patterns.
- Versatile: Can be used for web, mobile, desktop, cloud, gaming, IoT, and more.
C# on Linux offers several advantages:
- Cost-Effective: Linux is free and open-source, reducing infrastructure costs.
- Performance: Linux's lightweight nature can provide performance benefits for server applications.
- Containerization: Excellent Docker and Kubernetes support for cloud-native development.
- Integration: Better integration with other open-source technologies commonly used in Linux environments.
- Flexibility: Freedom to choose your preferred Linux distribution and tools.
Day 1: Environment Setup and First Steps
Setting up .NET on Linux
The first step in your C# journey on Linux is to install the .NET SDK (Software Development Kit). The installation process varies slightly depending on your Linux distribution.
| Distribution | Installation Commands |
|---|---|
| Ubuntu/Debian |
|
| Fedora/RHEL/CentOS |
|
| Arch Linux |
|
| openSUSE |
|
After installation, verify that .NET is correctly installed by running:
dotnet --info
This command should display information about the installed .NET SDK, including the version number, installation location, and available runtimes.
dotnet-install scripts or asdf with the .NET plugin.
Development Tools
While you can develop C# applications using just a text editor and the command line, using an Integrated Development Environment (IDE) or a powerful code editor can significantly enhance your productivity. Here are the recommended options for Linux:
Visual Studio Code
Visual Studio Code (VS Code) is a lightweight, open-source code editor that works excellently on Linux and provides rich support for C# development when configured with the right extensions.
Installation:
# Debian/Ubuntu
sudo apt-get install wget gpg
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg
sudo install -D -o root -g root -m 644 packages.microsoft.gpg /etc/apt/keyrings/packages.microsoft.gpg
sudo sh -c 'echo "deb [arch=amd64,arm64,armhf signed-by=/etc/apt/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" > /etc/apt/sources.list.d/vscode.list'
rm -f packages.microsoft.gpg
sudo apt update
sudo apt install code
# Fedora/RHEL
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
sudo sh -c 'echo -e "[code]\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/vscode.repo'
sudo dnf install code
# Arch Linux
sudo pacman -S visual-studio-code-bin
Essential extensions for C# development:
- C# Dev Kit - Comprehensive C# development support
- .NET Core Tools - Tools for working with .NET projects
- NuGet Package Manager - Manage NuGet packages
- REST Client - Test APIs directly from VS Code
- Docker - Docker integration for containerized development
JetBrains Rider
JetBrains Rider is a full-featured, cross-platform .NET IDE. While it's not free, it offers a comprehensive development experience with advanced features.
Installation:
# Download and install from JetBrains website
wget https://download.jetbrains.com/rider/JetBrains.Rider-2025.1.0.tar.gz
sudo tar -xzf JetBrains.Rider-2025.1.0.tar.gz -C /opt
/opt/JetBrains.Rider-2025.1.0/bin/rider.sh
Command Line Tools
The .NET SDK comes with a powerful command-line interface (CLI) that allows you to create, build, test, and publish .NET applications. Here are some essential commands:
# Create a new console application
dotnet new console -n MyFirstApp
# Navigate to the project directory
cd MyFirstApp
# Build the application
dotnet build
# Run the application
dotnet run
# Publish the application
dotnet publish -c Release
Your First C# Program
Let's create your first C# program on Linux. We'll create a simple "Hello, World!" application to verify that everything is set up correctly.
- Open a terminal and create a new directory for your project:
mkdir HelloCSharp cd HelloCSharp - Create a new console application:
dotnet new console - Open the generated Program.cs file in your preferred editor:
code Program.cs # If using VS Code - You'll see code similar to this (in C# 14):
// Program.cs Console.WriteLine("Hello, World!"); - Let's modify it slightly to make it more interactive:
// Program.cs Console.WriteLine("Welcome to C# development on Linux!"); Console.Write("Please enter your name: "); string? name = Console.ReadLine(); Console.WriteLine($"Hello, {name}! Today is {DateTime.Now:d} and the time is {DateTime.Now:t}."); Console.WriteLine("You're running .NET on Linux successfully!"); - Save the file and run the application:
dotnet run
If everything is set up correctly, you should see the welcome message, be prompted to enter your name, and then see a personalized greeting with the current date and time.
? after string is a nullable reference type indicator,
introduced in C# 8.0. It indicates that the variable can be null. This is part of C#'s null safety features.
Understanding the Project Structure
Let's take a moment to understand the structure of the project we just created:
HelloCSharp/
├── HelloCSharp.csproj # Project file containing configuration
├── Program.cs # Main source code file
├── obj/ # Directory for intermediate build files
└── bin/ # Directory for compiled output
The .csproj file is an XML file that contains project configuration, including target framework,
dependencies, and build settings. The Program.cs file contains the actual C# code.
Day 1 Exercise: Enhancing Your First Application
To practice what you've learned, try enhancing your first application with the following features:
- Ask the user for their favorite programming language
- If they answer "C#", respond with an enthusiastic message
- Otherwise, respond with a message encouraging them to give C# a try
- Add a loop that allows the user to repeat the interaction or exit
Resources and References
Here are some valuable resources to supplement your learning:
Official Documentation
Community Resources
Books and Courses
- "Pro C# 10 with .NET 10" by Andrew Troelsen and Phil Japikse
- "C# in Depth" by Jon Skeet
- "ASP.NET Core in Action" by Andrew Lock
- Pluralsight courses on C# and .NET
- Udemy courses on C# development
Remember, becoming proficient in C# and .NET development takes time and practice. This 7-day guide is just the beginning of your journey. Continue exploring, building, and learning to become a skilled C# developer on Linux!