Install Powershell and PowerCLI in Ubuntu 18.04 (Bionic Beaver)

A little while back I spoke about installing an unsupported version of Powershell in 18.04. Since the release of of Powershell 6.1.0-preview.2, it is now supported. Well, kind of. The release is still in preview, but hey, it natively installs at least.

What I can say about my experiences though is while I thoroughly enjoyed running on Ubuntu, I have decided to go back to windows as my primary OS due to certain incompatibilities, for example, lack of Webex (something we use VERY often at my company), terrible screen scaling as my laptop is attached to a doc with 2 1080p monitors and a 4k laptop monitor. Also, no native, freemium / open source alternative to outlook. I was looking at an all in one compatibility instead of separate apps to do little parts of something Outlook can do all in one, like calendar, contact management etc. I found an app called “MailSpring” which came REALLY close, but just didn’t cut it. Whilst I wouldn’t mind purchasing it, I was not too keen on the $8/m. Yeah, call me cheap, but they really should allow a “Pay Once” model.

So, lets begin:

References:

Install Prerequisites:

Curl:

root@epicworkstation:/home/raymond# apt-get install curl
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libcurl4
The following NEW packages will be installed
curl libcurl4
0 to upgrade, 2 to newly install, 0 to remove and 0 not to upgrade.
Need to get 373 kB of archives.
After this operation, 1,036 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://gb.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libcurl4 amd64 7.58.0-2ubuntu3.2 [214 kB]
Get:2 http://gb.archive.ubuntu.com/ubuntu bionic-updates/main amd64 curl amd64 7.58.0-2ubuntu3.2 [159 kB]
Fetched 373 kB in 0s (4,618 kB/s)
Selecting previously unselected package libcurl4:amd64.
(Reading database ... 164777 files and directories currently installed.)
Preparing to unpack .../libcurl4_7.58.0-2ubuntu3.2_amd64.deb ...
Unpacking libcurl4:amd64 (7.58.0-2ubuntu3.2) ...
Selecting previously unselected package curl.
Preparing to unpack .../curl_7.58.0-2ubuntu3.2_amd64.deb ...
Unpacking curl (7.58.0-2ubuntu3.2) ...
Setting up libcurl4:amd64 (7.58.0-2ubuntu3.2) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Processing triggers for man-db (2.8.3-2) ...
Setting up curl (7.58.0-2ubuntu3.2) ...
root@epicworkstation:/home/raymond#

Install Powershell (taken direct from Github Link)

root@epicworkstation:/home/raymond# # Import the public repository GPG keys
sudo curl -o /etc/apt/sources.list.d/microsoft.list https://packages.microsoft.com/config/ubuntu/18.04/prod.list

# Update the list of products
sudo apt-get update

# Install PowerShell
sudo apt-get install -y powershell-preview

# Start PowerShell
pwshroot@epicworkstation:/home/raymond# curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 983 100 983 0 0 7335 0 --:--:-- --:--:-- --:--:-- 7335
OK
root@epicworkstation:/home/raymond#
root@epicworkstation:/home/raymond# # Register the Microsoft Ubuntu repository
root@epicworkstation:/home/raymond# sudo curl -o /etc/apt/sources.list.d/microsoft.list https://packages.microsoft.com/config/ubuntu/18.04/prod.list
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 77 100 77 0 0 1040 0 --:--:-- --:--:-- --:--:-- 1040
root@epicworkstation:/home/raymond#
root@epicworkstation:/home/raymond# # Update the list of products
root@epicworkstation:/home/raymond# sudo apt-get update
Hit:1 http://gb.archive.ubuntu.com/ubuntu bionic InRelease
Get:2 http://gb.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:3 http://gb.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
Get:4 https://packages.microsoft.com/ubuntu/18.04/prod bionic InRelease [2,846 B]
Get:5 http://security.ubuntu.com/ubuntu bionic-security InRelease [83.2 kB]
Get:6 http://gb.archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [194 kB]
Get:7 http://gb.archive.ubuntu.com/ubuntu bionic-updates/main i386 Packages [176 kB]
Get:8 http://gb.archive.ubuntu.com/ubuntu bionic-updates/main Translation-en [77.7 kB]
Get:9 http://gb.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages [120 kB]
Get:10 http://gb.archive.ubuntu.com/ubuntu bionic-updates/universe i386 Packages [120 kB]
Get:11 http://gb.archive.ubuntu.com/ubuntu bionic-updates/universe Translation-en [52.6 kB]
Get:12 https://packages.microsoft.com/ubuntu/18.04/prod bionic/main amd64 Packages [17.2 kB]
Fetched 1,008 kB in 1s (1,545 kB/s)
Reading package lists... Done
root@epicworkstation:/home/raymond#
root@epicworkstation:/home/raymond# # Install PowerShell
root@epicworkstation:/home/raymond# sudo apt-get install -y powershell-preview
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
liblttng-ust-ctl4 liblttng-ust0 liburcu6
The following NEW packages will be installed
liblttng-ust-ctl4 liblttng-ust0 liburcu6 powershell-preview
0 to upgrade, 4 to newly install, 0 to remove and 5 not to upgrade.
Need to get 59.7 MB of archives.
After this operation, 162 MB of additional disk space will be used.
Get:1 http://gb.archive.ubuntu.com/ubuntu bionic/universe amd64 liblttng-ust-ctl4 amd64 2.10.1-1 [80.8 kB]
Get:2 http://gb.archive.ubuntu.com/ubuntu bionic/main amd64 liburcu6 amd64 0.10.1-1 [52.1 kB]
Get:3 http://gb.archive.ubuntu.com/ubuntu bionic/universe amd64 liblttng-ust0 amd64 2.10.1-1 [154 kB]
Get:4 https://packages.microsoft.com/ubuntu/18.04/prod bionic/main amd64 powershell-preview amd64 6.1.0~preview.3-1.ubuntu.18.04 [59.4 MB]
Fetched 59.7 MB in 9s (6,773 kB/s)
Selecting previously unselected package liblttng-ust-ctl4:amd64.
(Reading database ... 164790 files and directories currently installed.)
Preparing to unpack .../liblttng-ust-ctl4_2.10.1-1_amd64.deb ...
Unpacking liblttng-ust-ctl4:amd64 (2.10.1-1) ...
Selecting previously unselected package liburcu6:amd64.
Preparing to unpack .../liburcu6_0.10.1-1_amd64.deb ...
Unpacking liburcu6:amd64 (0.10.1-1) ...
Selecting previously unselected package liblttng-ust0:amd64.
Preparing to unpack .../liblttng-ust0_2.10.1-1_amd64.deb ...
Unpacking liblttng-ust0:amd64 (2.10.1-1) ...
Selecting previously unselected package powershell-preview.
Preparing to unpack .../powershell-preview_6.1.0~preview.3-1.ubuntu.18.04_amd64.deb ...
Unpacking powershell-preview (6.1.0~preview.3-1.ubuntu.18.04) ...
Setting up liburcu6:amd64 (0.10.1-1) ...
Setting up liblttng-ust-ctl4:amd64 (2.10.1-1) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Processing triggers for man-db (2.8.3-2) ...
Setting up liblttng-ust0:amd64 (2.10.1-1) ...
Setting up powershell-preview (6.1.0~preview.3-1.ubuntu.18.04) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
root@epicworkstation:/home/raymond#

Turns out, pwsh is not native yet. I had to do a snap install of it too.

root@epicworkstation:/home/raymond# pwsh

Command 'pwsh' not found, but can be installed with:

snap install powershell

root@epicworkstation:/home/raymond# snap install powershell
error: This revision of snap "powershell" was published using classic confinement and thus may
perform arbitrary system changes outside of the security sandbox that snaps are usually
confined to, which may put your system at risk.

If you understand and want to proceed, repeat the command including --classic.
root@epicworkstation:/home/raymond# snap install powershell -classic
error: unknown flag `c'
root@epicworkstation:/home/raymond# snap install powershell --classic
powershell 6.0.2 from 'microsoft-powershell' installed
root@epicworkstation:/home/raymond#

But, as it turns out, even that didn’t allow me to run pwsh as ‘/snap/bin’ was not included in the PATH environment variable

root@epicworkstation:/home/raymond# pwsh
Command 'pwsh' is available in '/snap/bin/pwsh'
The command could not be located because '/snap/bin' is not included in the PATH environment variable.
pwsh: command not found
root@epicworkstation:/home/raymond#

So, I added it to the environment variable and was able to launch Powershell.

root@epicworkstation:/home/raymond# export PATH="/snap/bin:$PATH"
root@epicworkstation:/home/raymond# $PATH
bash: /snap/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games: No such file or directory
root@epicworkstation:/home/raymond# pwsh
PowerShell v6.0.2
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/pscore6-docs
Type 'help' to get help.

PS /home/raymond>$PSVersionTable

Name Value
---- -----
PSVersion 6.0.2
PSEdition Core
GitCommitId v6.0.2
OS Linux 4.15.0-23-generic #25-Ubuntu SMP Wed May 23 18:02:16 UTC 2018
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0


PS /home/raymond>

Now, to install PowerCLI and verify it installed.

PS /home/raymond> Install-Module VMware.PowerCLI

Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install
the modules from 'PSGallery'?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): A
PS /home/raymond> Get-Module -ListAvailable Vmware* Directory: /usr/local/share/powershell/Modules ModuleType Version Name ExportedCommands ---------- ------- ---- ----------------
Script 6.7.0.8... VMware.DeployAutomation {Add-DeployRule, Add-ProxyServer, Add-ScriptBundle, Copy-DeployRule...}
Script 6.7.0.8... VMware.ImageBuilder {Add-EsxSoftwareDepot, Add-EsxSoftwarePackage, Compare-EsxImageProfile, Export-EsxImageProfile...}
Manifest 10.1.1.... VMware.PowerCLI
Script 6.7.0.8... VMware.Vim
Script 10.1.0.... VMware.VimAutomation.Cis.Core {Connect-CisServer, Disconnect-CisServer, Get-CisService}
Script 10.0.0.... VMware.VimAutomation.Cloud {Add-CIDatastore, Connect-CIServer, Disconnect-CIServer, Get-Catalog...}
Script 10.1.0.... VMware.VimAutomation.Common
Script 10.1.0.... VMware.VimAutomation.Core {Add-PassthroughDevice, Add-VirtualSwitchPhysicalNetworkAdapter, Add-VMHost, Add-VMHostNtpServer...}
Script 6.5.4.7... VMware.VimAutomation.HA Get-DrmInfo
Script 7.5.0.8... VMware.VimAutomation.HorizonView {Connect-HVServer, Disconnect-HVServer}
Script 10.0.0.... VMware.VimAutomation.License Get-LicenseDataManager
Script 10.1.0.... VMware.VimAutomation.Nsxt {Connect-NsxtServer, Disconnect-NsxtServer, Get-NsxtService}
Script 10.0.0.... VMware.VimAutomation.PCloud {Connect-PIServer, Disconnect-PIServer, Get-PIComputeInstance, Get-PIDatacenter}
Script 10.1.0.... VMware.VimAutomation.Sdk
Script 10.0.0.... VMware.VimAutomation.Srm {Connect-SrmServer, Disconnect-SrmServer}
Script 10.1.0.... VMware.VimAutomation.Storage {Add-KeyManagementServer, Copy-VDisk, Export-SpbmStoragePolicy, Get-KeyManagementServer...}
Script 1.2.0.0 VMware.VimAutomation.StorageUtility Update-VmfsDatastore
Script 10.1.0.... VMware.VimAutomation.Vds {Add-VDSwitchPhysicalNetworkAdapter, Add-VDSwitchVMHost, Export-VDPortGroup, Export-VDSwitch...}
Script 10.0.0.... VMware.VimAutomation.Vmc {Connect-Vmc, Disconnect-Vmc, Get-VmcService, Connect-VmcServer...}
Script 10.0.0.... VMware.VimAutomation.vROps {Connect-OMServer, Disconnect-OMServer, Get-OMAlert, Get-OMAlertDefinition...}
Script 6.5.1.7... VMware.VumAutomation {Add-EntityBaseline, Copy-Patch, Get-Baseline, Get-Compliance...}

All is completed.

Whilst there was fewer steps, I just wish they would build an installer that does it for you, from start to finish.

One Comment

    farid

    Awesome man, this is real neat info and detailed steps. Many thanks

Leave a Reply

Your email address will not be published.

*
*