This post is a guide on how to change a WSL distribution, from your default WSL Linux distro in the Windows Subsystem for Linux This is useful when you are managing multiple WSL distros on your computer.
List Installed WSL Distros
First up, we want to display your installed WSL distributions and versions by running the following command.
# show installed wsl distros & versions
wsl -l -v
The star at the distro name indicates the current default WSL Linux distribution.
When we enter WSL by running the wsl command, we will log into the Ubuntu-20.04 distro.
We can run lsb_release -a as above to verify which Linux distribution we are using.
Set Default WSL Linux Distro
To set the default WSL Linux distro we need to run wsl -s <wsl-distribution-name>
Before running this command, the WSL distro name is as-per what is shown in the wsl -l -v command.
# wsl show versions
wsl -l -v
# set default wsl distribution (as per 'wsl -l' name)
wsl -s <wsl-distribution-name>
Noticing here the same ‘lsb_release -a‘ command does not work for me when in the Debian distro – using cat /etc/os-release instead.
This is a post on how to install Postgres on Ubuntu 20.04, on Windows Subsystem for Linux (WSL). This should hopefully be a straightforward installation for you, which is done by following these 2 steps:
The next command will install Postgres. We’re including the ‘-contrib‘ package which will give us extra functionalities. After installing with the first command I need to restart the Postgres Service to resolve an “error: could not connect to server: No such file or directory” error message.
# install postgres on ubuntu
sudo apt install postgresql postgresql-contrib
# restart postgres service ubuntu
sudo service postgresql restart
Once the installation completes, we can enter psql using the ‘postgres’ user that was automatically created during the installation.
# login to psql with the out of box postgres user
sudo -u postgres psql
\q (to quit back to terminal)
To check your installed Windows Subsystem for Linux (WSL) versions, run wsl -l -v. This will show all installed WSL Linux distro names & versions.
WSL allows users to develop and run applications within a GNU/Linux environment on a Windows computer. Previous to this feature release we needed Virtual Machines (VMs), and dual boot setups were much more common if you wanted local test environments.
There are 2 versions of WSL, the old (1), and the new (2). We should ideally be using the latest version like all other software in existence, but there are use cases where we might prefer to use WSL Version 1.
As always, we should look for the most relevant MS Docs when researching a Microsoft Product or Application. The image below shows the current feature differences between WSL 1 and WSL 2.
To check the versions of your installed WSL distros, open a PowerShell Terminal and run wsl -l -v
# wsl check version
wsl -l -v
The command above lists all installed Windows Subsystem Linux distributions on your local machine, including WSL versions (WSL1 or WSL2) and their state (Running or Stopped).
I’m using Windows Terminal in this demo, which is great for managing multiple WSL distributions. We are able to open multiple Linux WSL distros and manage them using tabs as displayed in the screenshot above.
To install WSL (Windows Subsystem for Linux), we first enable the WSL Windows Feature using PowerShell, then install WSL Linux Distributions via the Microsoft Store.
This post will help guide you through enabling and installing Windows Subsystem for Linux (WSL) on your local Windows computer.
WSL allows Windows users to develop and run applications within a GNU/Linux environment. Previous to this feature release we needed Virtual Machines (VMs), and dual boot setups were much more common if you wanted local test environments.
The list of available Linux Distributions for installation, current as of this post date, includes the following:
– Ubuntu 20.04 (LTS / 18.04 LTS) – openSUSE Leap 15.1 – SUSE Linux Enterprise Server (15 SP1 / 12 SP5) – Kali Linux – Debian GNU/Linux – Fedora Remix for WSL – Pengwin (+ Enterprise) – Alpine WSL – Raft (Free Trial)
This blog post is a demo to help you install WSL for the first time on your Windows machine. FYI, there’s a reboot of your computer required at the end of the first step (enabling WSL).
You can find all the WSL Linux Distributions in the Microsoft Store which are available to download from there. This may be restricted by Group Policy if you’re on a Domain (a work/corporate computer).
To check our commit history on a Repository within Git, we use the git log command. When using this command we scroll through the commit log within our Terminal by hitting the Enter key, and then we need to hit q on our keyboard to exit reading the git log.
This post is to demo the --online parameter that can be added to the git log statement. Adding this parameter to the git log command will return a condensed commit log history, which shows the first part of the commit hash and message on one line.
In the following example, I’m running the standard git log command on one of my Repos. This is what we’d use if we want information including full commit hashes, commit dates/times, and authors.
You might think the above shows too many logs on the screen. We can pass in a line number parameter for it to return a specific number of commits.
This next example shows with and without the above –oneline parameter. We limit the number of commits/rows being returned by adding ‘-5‘ (can be any number).
# show most recent 2 commits
git log -2
# show most recent 5 commits on one line
git log -5 --oneline
We can amend the formatting of the returned list, including changing colours, adding in commit times, and adding the contributor.
This would be ideal if it was added as a function on your Terminal Profile.
# show most recent 5 commites on one line, with formatting
git log -5 --graph --pretty=format:'%C(red)%h%Creset -%C(yellow)%d%Creset %s %C(green)(%cr) %C(yellow)<%an>%Creset'
That’s it for this tip, check out my other posts on this topic in the Git Tag if of interest.
This is a post on how to change a Windows Subsystem for Linux (WSL) Distribution from running on Version 2 to Version 1.
WSL has two versions, the latest (2), and the original version (1). You can have many different Linux Distributions installed on your machine, and you can easily change the WSL Version for one of them.
This Microsoft documentation page explains the key differences between versions and will help explain why you might want to downgrade back to version 1 for your particular WSL development needs.
To change one of your WSL Distributions from WSL2 to WSL1, we just need to pass in the –set-version parameter and it’ll be converted very quick. I’m listing my available WSL Distro’s before and after to visually verify the change.
# check wsl distro versions
wsl -l -v
# change wsl distro using name above to desired version
wsl --set-version Ubuntu 1
This is a post on how to reboot a Windows Subsystem for Linux (WSL) virtual machine environment on your local machine. I’ve needed to do this a few times in the past year, my WSL instance throws some random error which was only resolved after a reboot.
As far as I know, we are unable to reboot from within WSL due to the lack of systemd. There are some open-source projects in the works to enable this which I’ve not tried yet. So we need to run a simple ‘wsl’ command to shutdown the host, and the enter WSL to get it back online.
This example shows exactly that, and I’m listing my installed WSL Distributions between each step.
# check wsl version
wsl -l -v
# reboot wsl2 instance
wsl --shutdown
# enter default wsl instance to boot
wsl
If you have multiple Linux Distributions installed on your Windows machine, by default you can only have one of them running, so when you’re switching between using ‘wsl -d <instanceName>’ the other will go offline. There is a way to get multiple WSL instances running at the same time, even with a GUI – have a look at this WSL Distro Manage project in GitHub if of interest.
One last note, the LXSS Manager Service is the broker to the Linux subsystem driver. We can also restart this service or of course reboot our local machine.
WSL allows users to develop and run applications within a GNU/Linux environment on a Windows computer. Previous to this Windows Feature you might have needed VM’s or a dual boot setup for this type of test/development environment.
There are 2 versions of WSL, the old (1), and the new (2). We should ideally be using the latest version like all other software in existence, but there are use cases where we might prefer to use WSL Version 1. This Microsoft documentation page explains the key differences between versions, and this post is to help explain how to check your WSL Version.
Personally I prefer to use WSL Version 2 as we’re able to make use of more apps like Docker. Also, I don’t need to worry about the exceptions for when it’s best to use WSL Version 1.
With descriptions out of the way, we can check our WSL Versions by running the following from a PowerShell Terminal –
# check wsl version
wsl -l -v
The above gives us a list of all installed Linux Distributions on your local machine including WSL Versions.
This is a post on how to help manage S3 Buckets with AWS CLI, and to help explain some local Operating System (OS) considerations when running such commands.
I’m more often involved in the PowerShell side rather than Linux. AWS CLI commands do the same thing in both environments, but the native (OS) language is used around it for manipulating data for output and for other things like wrapping commands in a For Each loop. All commands in this post can run on either OS.
PowerShell is cross-platform and has supported various Linux & DOS commands since its release. Some are essential for everyday use, for example, ping, cd, ls, mkdir, rm, cat, pwd and more. There are more commands being added over time like tar and curl which is good to see. Plus, we have WSL to help integrate non-supported Linux commands.
Here’s one of the simplest examples which list all S3 buckets the executing IAM User owns within your AWS Account.
# List all buckets in an AWS Account
aws s3 ls
The Default Region is configured during the AWS CLI Configuration as linked above. We can change this by running aws configure set region or configure your Environment Variables. Alternatively, we can pass in the –Region variable after ‘ls’ in the command to get a specific Region’s S3 Buckets. There are more ways for us to run commands across multiple Regions which I hope to cover another day.
Now I’m going to run a command to show me the Access Control List (ACL) of the bucket, using the list of Bucket Names I ran in the previous command. This time, I’m utilising the s3api command rather than s3 – look here for more information on the differences between them. When running AWS CLI commands these API docs will always help you out.
# Show S3 Bucket ACL
aws s3api get-bucket-acl --bucket my-bucket
Next up, I’m going to create a bucket using the s3 command rather than s3api. The reason I’m doing this is, I want to rely on my Default Region for the new S3 Bucket, rather than specifying it within the command. Here’s AWS’s explanation of this –
“Regions outside of us-east-1 require the appropriate LocationConstraint to be specified in order to create the bucket in the desired region – “ –create-bucket-configuration LocationConstraint=eu-west-1 AWS API Docs
The following command is creating a new S3 Bucket in my Default Region and I’m verifying the location with get-bucket-location afterwards.
# Change AWS CLI Default Region
aws configure set region eu-west-1
# Create a new S3 Bucket in your Default Region
aws s3 mb s3://pw-blog-bucket-101
# Check the Region of a S3 Bucket
aws s3api get-bucket-location --bucket pw-blog-bucket-101 --output text
And finally, to finish this off I’m going to: – Create a folder (known as Object) within the new Bucket. – List items in the S3 Bucket. – Copy a file from my desktop into the folder. – List items in the S3 Bucket. – Delete the Bucket.
# Create folder/object within a S3 Bucket
aws s3api put-object --bucket pw-blog-bucket-101 --key folder1/
# Show objects within S3 Bucket
aws s3 ls s3://pw-blog-bucket-101 --recursive --human-readable
# Copy a local file into the folder above
aws s3 cp .\Upload2S3.txt s3://pw-blog-bucket-101/folder1
# Show objects within S3 Bucket
aws s3 ls s3://pw-blog-bucket-101 --recursive --human-readable
# Delete the S3 Bucket
aws s3 rb s3://pw-blog-bucket-101
# List the S3 Bucket above (expect error)
aws s3 ls s3://pw-blog-bucket-101