How to Setup Bash on Windows 10 for Developers – Ultimate Setup

Bash for Windows 10 has been out for almost a year now. It has been incredible for a developer like myself to be able to use Bash natively on a Windows machine!

In this article, I’ll show you how I install my main Bash setup for Windows 10.

 

Requirements

  1. Your Windows 10 PC must be running a 64-bit version of Windows 10 Anniversary Update build 14393 or later.
    To find your PC's CPU architecture and Windows version/build number, open Settings>System>About. Look for the System type and OS Build fields.


    In this screenshot, I have a 64-bit operating system, x64-based processor and OS Build, 15063.138, so I fit the requirements.

 

Steps

  1. Install Bash on Windows 10
  2. Install ConEmu for tabs
  3. Must have Bash customizations
  4. Install VcXsrv Windows X Server for opening GUI applications

 

1. Install Bash on Windows 10

In order to run Bash on Windows, you will need to manually:

  1. Turn on Developer Mode
  2. Enable the “Windows Subsystem for Linux (beta)” feature

Open Settings -> Update and Security -> For developers
Select the Developer Mode radio button.

Developer mode is selected.

From Start, search for “Turn Windows features on or off” (type ‘turn’)
Select Windows Subsystem for Linux (Beta)

Windows Subsystem for Linux (Beta) is checked.

Hit OK. Installation will proceed, and afterwards, you will have to restart your computer.

After you restart your computer, you will be able to finish installing Bash on Windows 10.

Search for Microsoft Store.

From the Microsoft Store, find Ubuntu and download and install it.

From Start, search for “bash” (type ‘bash’) or it might already be open.

When you open bash, you will see a command prompt window.

Type "y" to continue.

The real “Bash on Ubuntu on Windows” shortcut will be installed. Bash on Ubuntu on Windows might already be installed through the Microsoft Store.

Now, you can open “Bash on Ubuntu on Windows” whenever you search for “bash”

Try opening Bash.  The first time you install Bash on Windows, you will be prompted to create a UNIX username and password.

After typing in a UNIX user name and UNIX password, you can use Bash the same way that you would use a terminal on Mac and Linux.

The biggest problem though is there are no tabs! Let’s fix the tab issue.

 

2. Install ConEmu for tabs

ConEmu is an amazing program that gives you terminal tabs, allows you to copy and paste the normal way with CTRL-C and CTRL-V, and run any combinations of shells including Command Prompt, Bash, Powershell, and more.

https://conemu.github.io/

Hi the Download button, which will take you to a redirected list of versions of ConEmu. I like to use the Preview version.

Run the executable. Select the x64 bit version of installation.

Hit Next on the next few prompts, which are the intro window, license and agreement, and settings. I leave everything by default.

Now, you are ready to install. Hit Install.

Hit Finish on the next prompt.

From Start, search for “ConEmu” (type ‘ConEmu’)

When ConEmu first starts, you will be brought to the Startup Settings. You have to select the default console that you want to open.

Find and select {Bash::bash} in the Specified named task section.

Now, whenever you open ConEmu, it will open to Bash by default! ConEmu is easy to read and smooth.

I like to pin ConEmu to the taskbar to be able to open bash quickly. Right click ConEmu’s icon and click Pin to taskbar.

To add a new tab on ConEmu, type WIN+W.

To switch to the right tab, type CTRL+Tab.

To switch to the left tab, type CTRL+Shift+Tab.

All ConEmu’s shortcuts are listed: http://conemu.github.io/en/KeyboardShortcuts.html

 

3. Must have Bash customizations

Bash on Windows 10 is great, but it could use a few customizations to make using it with Windows 10 files and programs easier!

First, we will adjust our ~/.bashrc.

nano ~/.bashrc

Use any text editor. On nano, type ALT+/ to go to the end of the file.

These configurations allow easy access to some of my favorite Windows related directories and programs.

I want to be able to change directory to the Windows C: drive easily and access my desktop, so I use aliases.

alias converts the given word into shortcuts.

I also want to be able to use Sublime, which is my go-to GUI text editor, so that I can type subl . and open the current working directory with Sublime.

I am using Sublime 3https://www.sublimetext.com/3

I want to be able to open any folder with File Explorer with open, so that I can open the current working directory with open .

I have a shortcut called linux to open the Ubuntu’s root folder with File Explorer.

Lastly, I have an alias called reload for reloading the ~/.bashrc to apply any new configurations.

Replace huyle with the username of your computer.

# Custom shortcuts
alias windows="cd /mnt/c"
alias desktop="cd /mnt/c/Users/huyle/Desktop"
alias subl="/mnt/c/Program\ Files/Sublime\ Text\ 3/subl.exe"
alias open="/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe /c start -WorkingDirectory C:'\\'Users'\\'huyle'\\'AppData'\\'Local'\\'lxss"
alias linux="open C:/Users/huyle/AppData/Local/lxss"
alias reload="source ~/.bashrc"

These other shortcuts I use to access my favorite directories. I recommend you to add your favorite Windows or Ubuntu directories where you put your development code or work.

# Optional shortcuts
alias repos="cd /mnt/c/Users/huyle/Desktop/Repos"
alias work="cd /mnt/c/Users/huyle/Desktop/Work"
alias youtube="cd /mnt/c/Users/huyle/Desktop/YouTube"

You can save your file with nano by using CTRL+O and then pressing Enter.

Now, we can apply these changes.

source ~/.bashrc

Use the windows alias to easily switch to your Windows files! You can try some of these other aliases!

open .

The open alias does not work with Ubuntu’s directories because of directory translation errors, but by default, at least, I set the alias to open the Ubuntu root directory.

Every now and then, I prefer using Sublime, so it’s very convenient to be able to type subl . in order to open current working directories with Sublime.

Here are some extra utilities that I like to install on Bash. These utilities are optional.

I like to use tmux, which is a terminal multiplexer. It lets you switch easily between several programs in one terminal.

I like tabs, but every now and then, I like everything in one terminal for a bird’s eye view.

I also like to use zip and unzip often to create zip files and extract them.

sudo apt-get install -y tmux zip unzip

Nice! Bash on Windows 10 with tabs and tmux feels so good. Your development is now super-charged!

 

4. Install VcXsrv Windows X Server for opening GUI applications

If you have ever wanted to open GUI applications through SSH connections, this step is for you.

By default, Windows 10 does not come with an X11 server by default. I’ve been using VcXsrv Windows X Server, but Xming also works.

You can download VcXsrv Windows X Server here:

https://sourceforge.net/projects/vcxsrv

Hit the Download green button.

I leave the settings by default.

You can open VcXsrv by searching for “vcx” on Windows 10 search.

I Allow access for VcXsrv Public networks.

Now that we have our X11 server open, we should adjust our ~/.bashrc a little bit to make sure that the DISPLAY value will be correct.

vim ~/.bashrc
# X11 server display value
export DISPLAY=localhost:0.0

Let’s test if our X11 server works! I like to install x11-apps for testing.

x11-apps contains xclock, which is great for testing GUI applications and X11.

sudo apt-get install -y x11-apps

Now, let’s run xclock.

xclock

Last but not least, let’s make sure that X11 will work on top of SSH connections.

mkdir ~/.ssh
vim ~/.ssh/config
Host *
    ForwardAgent yes
    ForwardX11 yes

Now, save the ssh config file and change its permissions correctly.

chmod 600 ~/.ssh/config

Afterwards, you should be able to use -X with ssh in order to enable the forwarding of X11 connections to VcXsrv.

ssh -X [email protected]_address

Great job! Good luck with your development. I’ve been finding this setup very comfortable as a developer!

How to Access Ubuntu Bash Files from Windows

If you installed Bash on Windows 10, and you want to get access to the files that you created on Bash from the Windows side, here’s what you need to do!

  1. Open File Explorer
  2. Click File on the top left, click Change folder and search options
  3. Click on View tab, make sure Show hidden files, folders, and drives is selected, Click OK
  4. Click on the folder directory address box, copy and paste: %localappdata%\lxss or C:\Users\{username}\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu##.##
  5. When you click Enter, you’ll be in the Bash directory (2017): C:\Users\{username}\AppData\Local\lxss
  6. You can access the files through Cygwin or File Explorer in the future

 

1. Open File Explorer.

 

2. Click File on the top left, click Change folder and search options.

 

3. Click on View tab, make sure Show hidden files, folders, and drives is selected, Click OK.

 

4. (2017) Click on the folder directory address box, copy and paste: %localappdata%\lxss

If you’ve downloaded Ubuntu recently in (2018), then the path is different:

A. Go to C:\Users\{username}\AppData\Local\Packages\

B. Start looking for folder with the Ubuntu version (example): CanonicalGroupLimited.Ubuntu18.04

C. Your final destination will be in the LocalState\rootfs folder:

 

5. When you click Enter, you’ll be in the Bash directory: C:\Users\{username}\AppData\Local\lxss

 

6. You can access the files through Cygwin or File Explorer in the future!

Easy Malware Removal Guide

You might be using your computer one day and notice that there’s some weird behavior occurring.

Maybe, it’s the random popups or system crashes, strange warnings or dialog messages, excessive network activity, and programs start misbehaving (randomly opening, crashing, or strange error messages), you might be infected with malware.

Here are some basic steps that you can take to remove the malware. Note, you are responsible for your own data so please be sure to perform any backups before attempting any malware removal.

These suggestions are not effective on all types of malware (crypto and others), and you should seek professional advice/help for serious infections.

 

What is malware?

Malware‘ is an umbrella term used to refer to a variety of forms of hostile or intrusive software including computer viruses, worms, trojan horses, ransomware, spyware, adware, scareware, and other malicious programs. It can take the form of executable code, scripts, active content, and other software. Source.

 

How do you get infected by malware?

Usually, it can be very difficult to determine the cause of infection. Take care to inspect any file or link before running/clicking on it when browsing the internet, and avoid unsafe websites which can contain exploits.

Don’t give permissions to unknown programs to run and make sure to keep programs updated – developers will patch exploits and other vulnerabilities through updates.

These steps can be run in normal mode without booting into safe mode. These steps assume that you can boot your computer normally without issues.

 

Removing Malware

  1. Run rkill (download and run). This will kill running malware processes, fix and repair your registry and other file extensions. Do not reboot after running this.
  2. Download and run Malwarebytes Anti Malware. Set these settings and run the scan. It will repair damage done and remove most malware.settings - detection - scan for rootkits threat scan and start scan
  3. Then, run AdwCleaner. Scan first, then clean any infected results. It’ll prompt you to reboot after successful cleaning. This will remove malware on your system.

To prevent future infections, make sure to avoid opening files you might not know the source of and visiting websites that don’t appear legitimate.

Obviously, its not always possible to avoid infection especially if a website you regularly visit gets compromised, but you can follow these simple steps to remove the malware!

How to Run App on Phone on Android Studio on Windows – Nexus 5

While running Android Studio, you can instantly connect an Android device via USB on Mac or Linux, and run a developing app on that device. What about Windows? For Windows, you’ll need to install the Google USB Driver before running your developing app on your Android device, phone, or tablet.

Official docs: http://developer.android.com/tools/extras/oem-usb.html

usbdriver

 

List of steps for Windows 7, 8, and 10

  1. Connect your Android device to the PC.
  2. Open Android Studio, open the SDK Manager, and install the Google USB Driver.
  3. Search and open Device Manager.
  4. Find and expand Other devices section.
  5. Right click the device name (i.e. Nexus 5) and select Update Driver Software.
  6. Browse my computer for driver software and click Next.
  7. Browse for the Google USB driver folder and click next to install the driver.

Connect your Android device to the PC. Easy enough. Plug your Android device via USB to your PC.

Open Android Studio, open the SDK Manager, and install the Google USB Driver. The SDK Manager can be opened by the following Android Studio icon:

sdkmanager

Click on Android SDK. Check off the Google USB Driver and hit OK to install.

googleusbdriver

Search and open Device Manager. You can use Windows search to find the Device Manager.

Find and expand Other devices section. Right click the device name (i.e. Nexus 5) and select Update Driver Software.

devicemanager

Browse my computer for driver software and click Next. Browse for the Google USB driver folder and click next to install the driver. The Google USB driver folder should be inside your C:\Users\*username*\AppData\Local\Android\sdk\extras\google\usb_driver\.

updatedriver

After installing, when running Android studio, you should be able to run any developing app project on your Android device. When you hit the play button on Android Studio, a prompt should pop up and ask what connected or virtual device you want the app to be run on. Select the connected Android device, phone, or tablet and voila! You will need to unlock your Android device to see the app immediately be run.

What’s new in Windows 10?

Windows 10

Windows 10 is the next best thing coming from Microsoft. Here’s a few things to keep in mind when you’re considering the switch.

Its free!

Windows 10 is free for most people – but if you’re running Windows 7 or Windows 8.1. Don’t worry, you have one year, until July 29th, 2016 to make the jump. If you miss out on the free upgrade for whatever reason, it’ll cost $119. To upgrade your existing installation, look for the windows icon in your notification bar – and enroll

Once the update is available for your system, it’ll prompt you to install. If you need to, you can put it off until you’re ready to make the switch. It can take a few days as Windows 10 is rolled out to all users, so don’t despair if it doesn’t appear immediately for you. If you’ve been regularly updating windows and the icon doesn’t appear for you, simple, just visit this link to do it manually.

During the reservation process, Windows will let you know if you have any incompatible hardware – make sure to install any updates for your devices beforehand so that you can use them with windows 10.

Windows will automatically scan for incompatible hardware.
Windows will automatically scan for incompatible hardware.

 

Easy upgrade

Windows 10 can be installed without you having to lose any files or settings! Some things will change and require reconfiguration, but if you’re coming from Windows 8.1 or Windows 7, everything should remain as you had it beforehand. After the upgrade, if you want to do a complete reinstall you’ll have the option for that as well. Just make sure you have your Windows Serial Key handy (if you lost it, use this script or Ultimate PID Checker to grab it from your system) and create a bootable DVD or USB.

 

Better Performance

Windows 10 brings a number of performance tweaks and other optimizations. If you’re using a graphics card, you’ll be compatible with DX12 if you have a recent graphics card from Nvidia or AMD.

Defragment your hard drive before upgrading – defragging will optimize fragmented files and disk usage. You’ll be modifying a lot of files on your hard drive when performing the upgrade. For Windows 7, you can start Disk Defragmenter. On Windows 8.1, if you right click your hard drive in My Computer and go into Properties,  you’ll have the option to run Disk Defragmenter as well.

You’ll also want to run “Disk Cleanup” and “Clean System Files,” which will remove all the crud that’s been building up in your computer and free up some space.

 

Security and Anti Virus/Malware

Windows 10 will come with its own anti-malware software, Windows Defender (originally Security Essentials). If you want to use your own, make sure to check for updates and other maintenance before starting the upgrade to make sure they’ll work in Windows 10.

Those are just a few overall changes to Windows 10 as an operating system from previous iterations. Go upgrade now!

How to Get Your Windows Product Key

It’s harder than I thought to get your current installation’s of Windows 7, 8, or 10’s product key. There’s no easy way to find it except for this nice script.

1) Open Notepad

Search for the Notepad program that comes with every installation of Windows. When you open Notepad, an Untitled instance of Notepad should open.

notepad-open

 

2) Copy and paste the following script into Notepad:

File, Save As

File name: product-key.vbs
Save as type: All Files

saveasproduct-key

 

3) Double-click product-key.vbs to see your product key!

windows-product-key

How to take Screenshots on Windows 7 and 8

There’s a few different techniques for screenshotting on Windows, starting with the ubiquitous PrintScreen button. This button is usually found above the Insert, Home, and Page Up Button on your keyboard, but this depends on the type of keyboard you have and may not even be its own dedicated button on laptops. If you don’t have easy access to the PrintScreen key, don’t worry, read on.

 

With the PrintScreen Key

Using the PrintScreen key, a simple press will screenshot your entire workspace, taking a snap of everything you’re looking at, including things on other screens if you have multiple monitors or if you’re hooked up to a projector. Your screenshot is saved to your clipboard, so you can easily paste it into anything that you’ll need. I like to put it in Paint, so I can quickly review it and even crop pieces out that aren’t relevant to the screenshot. However, if you’re doing that – there are better options.

 

Alt + PrintScreen

Pressing ALT and the PrintScreen key (PrtScn on some keyboards) will allow you to quickly grab a screen capture of the current window. Note that this means the current window that has focus, the window that you’re currently using. You can avoid any mistakes by selecting focus with ALT + TAB, or just simply clicking on the window. You can paste it into whatever you need, Paint is my preference.

 

Snipping Tool

Third and my favorite way to quickly grab a screenshot is using the snipping tool. This tool comes with all installations of Windows 7 and above, and allows you to quickly select what you want in your screenshot. Simply click on "New", and once your cursor changes into a cross, you can click and drag to select what’s going to be included in your screenshot. Once you release your click, you’ll be able to review the screenshot and save it wherever you need it.

Untitled
Example full Windows screenshot

That’s it! Easy choices for screenshots in Windows 7 and 8.

8 Steps to Install Cygwin on Windows

Cygwin provides the Linux feeling on Windows. With Cygwin, you can get a sizable Linux collection of GNU and Open Source tools including a terminal that supports POSIX interface on Windows.

Step 1)

Check whether your System type is 32 bit or 64 bit. If you have Windows 8 or 8.1, right click on This PC on your Desktop, then click on Properties. If you don’t have This PC on your Desktop, you can also use Windows’ search to look for “This PC“, then right click the icon, and click on Properties.

On the Properties of This PC, you can see the System Type underneath System category. For me, System type: 64-bit Operating System, x64-based processor. I have a 64 bit operating system.

Right Click on This PC, Click on Properties, and Look at your System type.

 

Step 2)

Go to https://cygwin.com/install.html

Select the blue linked executable setup based on your system type of Step 1. Download will start automatically after clicking on one of the blue executable setup links.

Click on the executable setup based on your System type. Download starts automatically.

 

Step 3)

Open the executable Cygwin setup file. Run the set-up as normal. Click on Next on the Cygwin Setup screen.

When choosing Installation Type, select Install from Internet (default). Click Next.

When choosing the Installation Directory, you can leave the root directory by default, which will be C:\cygwin64 (64 bit). Install for all users. Click Next.

The Local Package Directory contains the setup installation files for packages that you wish Cygwin to have. Underneath Select Local Package Directory, the default is the directory where you have the setup executable.

You can leave this by default.

For Setup your Internet Connection, use Direct Connection for your Internet Connection if you’re using wi-fi or ethernet. Click next.

Choose a Download Site. Select any of the download sites. Click Next.

Cygwin Setup

 

Step 4)

You’ll now be at Cygwin Setup – Select Packages. From here, you can search for packages that you wish Cygwin to have. The ones that I recommend are:

For each of these packages, they belong to categories. Search for a package. Click on the + next to a category to expand the contents of the search. Click on the circle twirl with the arrows to select the most up-to-date version of that package. Package names are on the right with a short description of that package.

Example of selecting the latest version of nano to install.

 

Step 5)

After selecting a version to install for all your packages, you can click the next button at the bottom right of the setup screen. At the Resolving Dependencies screen, make sure that the checkbox that says Select required packages (RECOMMENDED) is checked. Click Next. The download and installation of your desired packages will commence.

Resolving Dependencies.

 

Step 6)

After you finish the download and installation, you can check Create an icon on Desktop. Click Finish. You’ll find a program called Cygwin64 Terminal on your desktop. Open the program. Cygwin is installed.

Installation of packages has finished. Finish.
When you open Cygwin for the first time, Cygwin initializes.

 

Step 7)

You can also add the Cygwin packages and POSIX interface for the Windows command prompt. In other words, you can make the command prompt act like the terminal in Linux.

Right click on “This PC” and click Properties if it’s on the Desktop. Also, you can use Windows’ search for “This PC” and right click, then click on Properties.

Click on Advanced System Settings in this Properties window.

In the System Properties that pops up, click on Environment Variables, which will be within the Advanced tab. Inside Environment Variables, look underneath the System variables section. Scroll through and look for the Variable with the name Path. Click on that line. Click on the Edit button underneath. For 64 bit, add a “;C:\cygwin64\bin;” to the end of the Variable value line. This allows the command prompt to work with Cygwin’s directory path to the Cygwin’s bin folder and utilize Cygwin’s packages and POSIX interface. Click OK for each of the three windows to save this setting.

Cygwin’s path variable to work with the command prompt.

 

Step 8)

Open a command prompt. You can use Windows’ search and search for command prompt or cmd. Click on command prompt, and a command prompt black box will open. You will have all the functionality of Cygwin within the command prompt. You can choose to use either Cygwin or a command prompt to use the linux tools or POSIX interface.

Displaying SSH on a Windows command prompt.