Tinus EngOps Wiki

Logo

OpsaC - Operating as PowerShell code

Links

Home

PowerShell Blog

PowerShell Index

PowerShell Search

Additional Websites

View my GitHub Profile

View my GitHub Gists

View Tinus IT Wiki

View my Photo Website

Install PowerShell on Linux

published: March 14, 2024 author: Tinu tags: PowerShell - News categories: PowerShell-Cross-Platform


Sometimes, I would playing araound with Linux and test some Modules.

Table of Contents

Windows Subsystem for Linux

Using the Windows Subsystem for Linux on Windows to use Linux. To install WSL on your Windows, consult the Install Guide on Microsoft.

List valid distributions

wsl --list --online

The following is a list of valid distributions that can be installed.
Install using 'wsl.exe --install <Distro>'.

NAME                                   FRIENDLY NAME
Ubuntu                                 Ubuntu
Debian                                 Debian GNU/Linux
kali-linux                             Kali Linux Rolling
Ubuntu-18.04                           Ubuntu 18.04 LTS
Ubuntu-20.04                           Ubuntu 20.04 LTS
Ubuntu-22.04                           Ubuntu 22.04 LTS
OracleLinux_7_9                        Oracle Linux 7.9
OracleLinux_8_7                        Oracle Linux 8.7
OracleLinux_9_1                        Oracle Linux 9.1
openSUSE-Leap-15.5                     openSUSE Leap 15.5
SUSE-Linux-Enterprise-Server-15-SP4    SUSE Linux Enterprise Server 15 SP4
SUSE-Linux-Enterprise-15-SP5           SUSE Linux Enterprise 15 SP5
openSUSE-Tumbleweed                    openSUSE Tumbleweed

Install a Linux

Install an Ubuntu on WSL.

wsl --install Ubuntu-22.04

Uninstall a Linux

Uninstall Ubuntu on WSL.

wsl --unregister Ubuntu-22.04

Install PowerShell on Ubuntu

The best way to use Linux is PowerShell:

sudo apt-get clean all && sudo apt-get update
sudo apt-get install -y wget apt-transport-https software-properties-common
wget -q "https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/packages-microsoft-prod.deb"
sudo dpkg -i packages-microsoft-prod.deb
sudo apt-get install -y powershell

List and Update PowerShell on Ubuntu

sudo apt list powershell

Output:

Listing... Done
powershell/jammy,now 7.4.1-1.deb amd64 [installed]
N: There are 28 additional versions. Please use the '-a' switch to see them.
sudo apt-get install --only-upgrade powershell

Install PowerShell on AlmaLinux

To install AlmaLinux, open Microsoft Store, search for AlmaLinux 9 and install it. It’s not available as WSL-Distribution

sudo dnf clean all && sudo dnf update && sudo dnf --security update
curl https://packages.microsoft.com/config/rhel/9.0/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo
sudo dnf install --assumeyes powershell

List and Update PowerShell on AlmaLinux

sudo dnf list powershell

Output:

Installed Packages
powershell.x86_64    7.4.1-1.rh    @packages-microsoft-com-prod
sudo dnf update powershell

Login on Linux

Start the Windows Terminal and open AlmaLinux-OS 9 or Ubuntu 22.04.3 LTS as a new tab.

StartLinux

Transfer data between Windows and Linux

List the local drives on Windows from the Linux:

ls /mnt

c  d  e  f  wsl  wslg  z

List the content of a specified path on Windows from the Linux:

ls /mnt/d/temp

Copy the profile.ps1 from Windows to Linux for all users. If you don’t have the profile.ps1 for cross-platform, here you find an example.

mkdir -p /home/tinux/.config/powershell
sudo cp -f -R /mnt/d/profile.ps1 /opt/microsoft/powershell/7/

Start PowerShell as user and then as root, that you can test the coloring of the profile.ps1.

Tip: In Windows Terminal press Alt and click the dropdown to select your Linux that you want to start. This split the current Terminal.

AlmaLinux9

Install Modules on Linux

First, set the PowerShell Gallery as trusted then you can install the modules without to confirm that you trust the repository.

Set-PSRepository -Name PSGallery -InstallationPolicy Trusted -SourceLocation https://www.powershellgallery.com/api/v2

Get-PSRepository

Name                      InstallationPolicy   SourceLocation
----                      ------------------   --------------
PSGallery                 Trusted              https://www.powershellgallery.com/api/v2

Start PowerShell as root to install modules for all users. I want to use two of the Modules from Jeff Hicks.

sudo pwsh
Install-Module -Scope AllUsers -Verbose -Name PSReadLine
# Jeff Hicks Modules
Install-Module -Scope AllUsers -Verbose -Name mySQLite
Install-Module -Scope AllUsers -Verbose -Name PSWorkItem
exit

Start PowerShell as user and initialize PSWorkItem and start the TUI Console.

pwsh
Initialize-PSWorkItemDatabase

Add-PSWorkItemCategory -Category Work -Description "business-related tasks" -PassThru -Force
Add-PSWorkItemCategory -Category Personal -Description "personal-related tasks" -PassThru -Force
Add-PSWorkItemCategory -Category Project -Description "project-related tasks" -PassThru -Force
Add-PSWorkItemCategory -Category Other -Description "something-related tasks" -PassThru -Force

Open-PSWorkItemConsole

or direct from bash

pwsh -Command "& {wic}"

PSWorkItem

See also

Getting Started with PowerShell in Linux, AlamLinux Wiki, Jeff Hicks PSWorkItem


← Previous Post [ Top ] Copyright © 2024 by tinuwalther [ Blog ] Next Post →