Rust on Linux

Enter the new uncomfort zone with Linux and Rust. This post documents the process and will serve as a reference for later usage.

Setup a Linux box

Having another machine with Linux operation system is cool but not necessary. Welcome to the Windows Subsystem for Linux 2 (WSL 2).
I am on Windows 11, I follow the instruction from Microsoft Docs.
With the Terminal and Powershell installed, run the command

wsl

The terminal displays the help with possible commands. I want to understand them a bit before actually executing any command.

wsl --list --online

Displays all the distributions. The Ubuntu is the default if none is specified. Let’s use the default. Remember to run as Administrator

# Explicitly specify the distribution for clarity
wsl --install --distribution Ubuntu

Nice! Installed and rebooted.

Create a folder (dir) to store code

$ mkdir code

Visual Studio Code with WSL

I am following the document here.

  • Install Remote Development extension
  • Navigate to the Ubuntu terminal, type code .. Magic begins

Rust on Linux

The Rust documentation is rich. I follow its programming book

$ curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh

After successfully installed Rust on Linux box, I need to restart the shell. It is to ensure that system understands the new environment variables. Otherwise, it does not understand the changes

# This will not recognize as a command
$ cargo
# Reset the profile/shell (bash shell)
$ source ~/.profile
# This will work
$ cargo

Write some code and struggle

fn main() {
    println!("Hello Rust 101");
}

I got the first error "linker ‘cc’ not found"
Ok. Get it the linker

$ sudo apt install build-essential

Enjoy the fruit

# Compile the code
$ rustc ./main.rs

# Run it
$ ./main

Summary

So what have I accomplished so far? I have setup a new development environment which includes

  • A Linux box running on Windows 11 using WSL 2
  • Visual Studio Code remote development. It allows me to stay on the Windows and write code in the Linux box. It is neat and straightforward. VS Code is amazing
  • Install and write a "hello word" rust application

What a great way to start a weekend!

Hi, Docker and Ubuntu

I was watching #MSBuild2017, looking over the balcony, up to the cloud, a voice whisper in my head, Oh man, you are far behind. What a moment! So many new things, I decided to pick Docker as a starting point. Honestly, I had no clue where to start. However, I did know that I had to start somewhere. A wise man said start small. Docker has just that, a hello world application.

Whenever I want to learn something, I head over to Pluralsight. Here we go. Give me Docker

Pluralsight Give Me Docker
Pluralsight Give Me Docker

I decided to take the Getting Started with Docker, then later Docker Deep Dive (still enjoying this course). They are awesome. The author, Nigel Poulton, has a good sense of humor.

Docker on Windows

I have been using Windows since I first met a computer. It is fairly simple to run and try out docker on Windows. Head over to Docker on Windows, download and follow the instruction.

After installation completed, fire up PowerShell, your very first command is docker version.

Your very first docker command

Have not used Command Line Interface for years, that output gave me a strong feeling. I uttered “wow it is cool“.

You cannot imagine my feeling when I ran this command

Hello World from Docker

From that moment, I know that I can do many things with the abilities Docker gives.

Docker on Linux

Here is another fact. I do not know Linux. I have not used any Linux system. Years ago, it was hard to setup a Linux lab. What is now?

Hyper-V The power of virtualization

With the power of Hyper-V, I can have as many machines as I wish. I decided to download and try with Ubuntu server (The course suggested it as well).

Installing Ubuntu on Hyper-V is simple. Download Ubuntu Server here. Hello Ubuntu.

Hello Ubuntu

Let try docker

Hello World on Ubuntu

Such an amazing moment 🙂 They are exactly the same in both versions.

Values?

Sound a trivial task. However, there are many things that I gained during the weekend.

  1. It triggers my learn process. I feel energized again after years of writing code.
  2. It opens opportunities. The more I know, the better I am. The better I am, the more opportunities I see.

What I showed here is the end result. Just like anything else in the world, the devil is at the detail. When you actually get your hands dirty, you will meet the roadblocks. Solving them gives me some Linux pieces.

Some Linux (Ubuntu Server) Command Line I learned

sudo su: Run as administrator (mapped to Windows environment).

ifconfig: Same as ipconfig in Windows.

ip addr show: Display the IP addresses with other information

route -n: Display kernel routing table.

apt-get install [name]: Install a package. For example: apt-get install docker.io will install docker on your Ubuntu

apt-get update: Install all updates.

service [name] status: View status of a service [name]

Not a bad result for my weekend. Not mention that I, now, love the Command Line approach.

 

So far so good. It is enough for me to move on. My next challenge is how to take advantages of them. It would be fun.