Update: As of Summer ’18 the CLI is no longer officially support within the Windows Subsystem for Linux. As you can see from the slightly tongue and cheek title, there is a lot of modification to the standard installation of Ubuntu within WSL to enable the browser to communicate with WSL. The following information applies to Ubuntu using Chrome as the browser. Various hardware systems, specifically graphics cards, may prevent this approach from working and is therefore not supportable.
The Salesforce CLI works great out of the box for Windows, Mac and a standalone Linux system. This means that it should work equally well in the Windows Subsystem for Linux (WSL) — and in fact, it does. But what makes it a bit tricky is that WSL runs headless. That means that there is no GUI for WSL out of the box. Without the GUI, it is difficult to initially authenticate to a hub org using the
sfdx force:auth:web:login command.
WSL does allow the launch of other installed Windows applications, but for the communication back to the CLI after successfully logging in via the browser, the native Windows browsers are not useful.
To be able to both login via the browser and easily open orgs from WSL you need to install a few extra bits. A native browser implementation needs to be installed into the WSL distro, an XWindows server needs to be installed on the Windows 10 host and few changes need to be made to some of the software installed by default for WSL distro.
The steps below get you up and running with WSL and Salesforce DX. This can take anywhere from 30 minutes to an hour depending on your internet connection speeds.
Enable WSL in Windows 10. This is done by using the Windows Features Control Panel applet. The easiest way to get to this screen is to enter “Turn Windows features on or off” in the search bar in your Cortana search. A Windows restart is required after enabling WSL.
Download and install the Ubuntu distribution from the Microsoft Store. Once downloaded and installed, type Ubuntu in the Windows 10 search box and launch Ubuntu. This will install a fresh Ubuntu image. The installation takes a few minutes and after it finished you will be prompted for a new Linux username and password.
Install Node Version Manager (NVM) for Linux and Node.js 10.0.0. If you haven’t used NVM before, it’s a tool that enables you for example to use different versions of node.js simultaneously on a machine as well as installing the Salesforce CLI without needing sudo.
You can verify the install of npm and node.js by using the commands below.
Install and verify the Salesforce CLI. The first command will install the CLI as global npm module.
WSL includes a version of OpenSSH that is insufficient for use with XWindows, so we need to remove the installed OpenSSH version and install the full OpenSSH version.
Edit the OpenSSH configuration file as follows:
Things to do in
- Add the following and replace
yourusernamewith your Linux username:
- Change the default port from
Install an XWindows Server, where Xming or VcXsrv are two good choices. I’ve had good luck with VcXsrv (and it’s free) so that is what we will use here. You can download a Windows installer from here. Launch the installer and accept all the defaults for installation.
Install Google Chrome into the Ubuntu distribution. This would likely work with other browsers, though I’ve only tested with Google Chrome. The key is that it is natively installed into Ubuntu.
Set the display in
.bashrc by editing the file with this command:
Add the following line at the end of the file:
Save the file and reload it for the current bash session:
Launch VcXrv with multiple windows and accept all defaults and verify that everything is working. Authenticate with your Dev Hub and create then a new scratch org based on the Dreamhouse sample app.
At this point you can now use the Salesforce CLI like a champ from WSL in Windows 10.
For more on using the Salesforce CLI, check out the App Development with Salesforce DX module on Trailhead.