Getting Started

Install Dependencies

If you’re like me you are probably raring to get going and start building your personalized IDE. I know it is tempting to dive in quickly, but getting some of this foundational work out of the way first will make things flow much more smoothly later on. In this chapter I will walk you through setting up your computer for the tasks ahead. If you are a Windows user I will walk you through installing the Windows Subsystem for Linux. This will allow you to run Ubuntu on Windows without having to install a VM. Next you will install Git, if you don’t already have it, to maintain a history of your configuration settings. You will then alter the layout of your keyboard slightly to make the keyboard shortcuts much easier to type. Next, I will discuss the actual Terminal application and its settings for each operating system. I’ll introduce you to the nano text editor that will be used until Vim is introduced later on. Finally, you will create the initial Git repository that will store your Terminal IDE configuration and scripts.

Windows Subsystem for Linux

The Windows Subsystem for Linux, which I will shorten to WSL from here on out, is a full Linux environment that runs natively on Windows 10. It provides a Linux command line and all of the capabilities of the Linux Distribution you install without having to run a virtual machine. You will, however, need to be running the latest version of Windows 10, and it must be the 64-bit version of Windows. WSL does not work on 32-bit Windows. Follow the steps below to enable and configure WSL for your system.

Enable WSL

In order to use WSL you need to first enable it for your system. Follow the steps below to enable your machine to use WSL.

  1. Click the Windows logo to open the Start Menu.
  2. Scroll down the list of applications until you find Windows System.
  3. Click on Windows System to open the section.
  4. You should see Control Panel. Click to open it.
  5. In the Control Panel window find and click on Programs.
  6. Click on Programs and Features.
  7. You will see a list of your installed programs.
  8. Click on Turn Windows features on or off in the left section of that window.
  9. A Windows Features dialog box will open. Scroll the list to the bottom.
  10. Click the checkbox next to Windows Subsystem for Linux.
  11. Click the OK button in the dialog.
  12. Follow the prompts to restart your computer.

Install a Linux Distribution

Once the Windows Subsystem for Linux is installed and your computer has restarted you will need to install a Linux distribution. Open the Microsoft Store application, click the magnifying glass icon in the top menu and search for Linux. You should see the Linux on Windows section shown below.

Windows Store Linux Applications
Windows Store Linux Applications

Click the Get the apps button and you will have a choice between Ubuntu, openSUSE, SUSE Linux Enterprise Server, Debian GNU/Linux and Kali Linux. I suggest picking Ubuntu in order to maximize compatibility with the rest of this book. Click Ubuntu distribution, then click the Get button to install it. Once the installation is complete you can start Ubuntu from the Launch button in the Microsoft Store or by clicking Ubuntu in the Start Menu.

The first time you launch Ubuntu it will perform an additional installation step.

WSL Installing Ubuntu
WSL Installing Ubuntu

When the installation step is complete you will be asked to create a new UNIX user name and password. This will create your user account on Ubuntu. Once that is complete you should see the Ubuntu command prompt which will contain the user name you just created, your computer name, the current directory (which is your home directory, denoted with the tilde character) and the prompt character which is a $ by default.

You now have a version of Ubuntu running on your Windows machine. The sections covering Ubuntu will be the relevant sections for you to use. If there is something different about Ubuntu on Windows I will call it out with a note.

Installing Git

I will cover installing Git on Ubuntu and macOS below. If you are not using one of those operating systems you will likely find Git installation instructions at the official Installing Git page.

Ubuntu

Installing Git on Ubuntu is the most straightforward of any of the operating systems covered. If you haven’t done so recently you should update and upgrade Apt so it has the most recent packages.

$ sudo apt update
  $ sudo apt upgrade

The update command will make sure the Apt packages are the most current packages available. The upgrade command will upgrade any installed packages to their most current versions. It might take a few minutes the first time because there are many upgrades to catch up with. This is a good thing to do from time to time just to get security and bug fixes. Now you are ready to install Git.

$ sudo apt install git

For additional options or instructions for installing Git on other Linux distributions go to the official Git Linux install page.

Git On macOS

Installing Git on macOS can be done in a couple different ways. You can use the version of Git that comes with the Xcode command line tools, or install the latest version of Git with Homebrew. I would suggest using the Xcode command line tools option because it will give you many other tools that will come in handy for development.

Xcode Command Line Tools

To install along with the Xcode command line tools simply open a terminal and enter:

$ git --version

That will trigger the Xcode command line tools installer to run. Follow the instructions in the dialog that pops up.

It is worth noting that the version of Git supplied by the Xcode command line tools is a little bit out of date. As of this writing the version is 2.17.2, and the most current version of Git is 2.19.2. There isn’t enough of a difference to cause a problem, but if you wish to have the latest and greatest you should consider the Homebrew option below.

Homebrew

To install Git with Homebrew you will first need to install it. Homebrew is a package manager, similar to Apt, for macOS. You can read more about Homebrew at the official website. To install Homebrew open your terminal and enter the following command line:

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

The Homebrew install script will run. Follow the instructions shown in the script. Once that is complete you can use Homebrew to install Git.

$ brew install git

Git Setup

Once you have Git installed you will need to set your user name and email before you can push any code to remote repositories. Use the git config command to set these values appropriately.

$ git config --global user.name "Your Name"
  $ git config --global user.email you@domain.com

Using the --global flag will make the configuration setting available to all of the repositories on the current machine, so you will not need to set these values for each project.

Optional Font

I like to use a specific font for my terminal and editor. Anonymous Pro is a free monospace font that can be downloaded from its creator’s website. Scroll to the bottom of the page and do not be fooled by the ‘Where To Buy’ heading. It is a free font and will download as a Zip file when you click the ‘Download Anonymous Pro’ link.

Once the Zip file is downloaded extract the contents and follow your operating system instructions for installing fonts.

Keyboard Tweaks

There are two things to cover when it comes to keyboards. First and foremost you should really be able to touch type in order to make full use of the techniques covered in this book. Touch typing isn’t hard to learn. I spent the first ten years of my development career using only two fingers of each hand to type. After all of that time I had a good feel for the keyboard, I know where all the keys were, but I wasn’t as fast as I could have been. I used Mavis Beacon Teaches Typing for about an hour a day for two weeks and it improved my speed considerably. There are a number of free touch typing tools available on the web now so there is no reason to not practice touch typing.

Secondly we are going to change where the <Control> key is located. Because we will be touch typing from now on we want to make it as easy as possible to reach the main function key that we will be using. The <Control> key figures in heavily with both tmux and vim, so it will be moved to the home row of your keyboard. If you look at your home row, where your fingers naturally sit, just to the left of the A key is <CapsLock>. I never use <CapsLock>. I would hazard a guess that most people do not use <CapsLock>. If you do, it is very infrequently. Why waste that prime keyboard real estate on a key that is rarely used? This is where we will relocate the <Control> key. Depending on the operating system you are using this is either very easy, or somewhat difficult. I will walk you through the change for Ubuntu, macOS and Windows below.

Ubuntu Control Key

Remapping the <CapsLock> key on Ubuntu requires installing a utility called Gnome Tweaks. This is assuming you are using Gnome and Ubuntu 18.04 or higher. Install the utility with the following command.

$ sudo apt install gnome-tweak-tool

Once the install is complete start the application from the command line.

$ gnome-tweaks

A window will appear with a list of tweaks. Pick Keyboard & Mouse from the list on the left. You will then see a page of Keyboard and Mouse options. Click the Additional Layout Options button at the bottom of the Keyboard section. Another smaller window will open with a list of options. About half way down the list click on Ctrl Position to open the list. You will see a number of checkboxes with different Ctrl key options. Select the Caps Lock As Ctrl checkbox.

Gnome Tweak Tool UI
Gnome Tweak Tool UI

macOS Control Key

Remapping the <CapsLock> key on macOS is pretty painless. First, open System Preferences, then select Keyboard. Click the Modifier Keys… button at the bottom of the Keyboard settings panel. A dialog will open listing all of the modifier keys. Next to the Caps Lock Key click the drop down menu and select Control. Click Ok in the dialog and then close System Preferences.

macOS System Preferences
macOS System Preferences

One thing to pay attention to, however, is that the setting is keyboard specific. If you notice at the top of the Modifier Keys… dialog there is a drop down menu that lists all of the keyboards the machine knows about. If you attach a Bluetooth keyboard it will be listed as a separate keyboard. Make sure you set the <CapsLock> Key for all of the keyboards you use.

Windows Control Key

I’m going to punt the Windows 10 remapping steps to a website. Remapping the Caps Lock key on Windows involves making changes to the Windows Registry. There are some older applications available that can make the necessary registry entries for you, but downloading an application for this one simple change feels like overkill. John Haller has a page dedicated to the Caps Lock key at his site. It does a good job of describing the process and provides Registry (.reg) files for making the necessary changes. There is even a file for reverting the Caps Lock key back to its normal state. You will need to restart the machine in order for the changes to become active.

Terminal Setup

All operating systems come with a built in Terminal application. In some cases the default Terminal is completely capable of handling everything that will be covered in this book. In other cases you will be better off switching to a third party Terminal application. Specifically you will want to use a Terminal that supports True Color mode. This will be required for some of the color themes that will be used later in the book.

Ubuntu

The default Terminal that comes with Ubuntu works well and supports True Color mode, so there is no reason to change it. The Terminal is conveniently placed on the Favorites bar for you by default, so just click the Terminal icon to start it.

Gnome Terminal on Ubuntu
Gnome Terminal on Ubuntu

Preferences

You can open the Terminal Preferences window by clicking the Terminal menu at the top of the screen. From the drop down menu select Preferences.

The General and Shortcuts settings do not need to be changed, so skip down to the Profiles section. Click the default profile, then click the drop down arrow to the right of the name and select Rename… to rename the profile. Name it anything you like, for the book it will be called Development.

Gnome Terminal Profile Naming
Gnome Terminal Profile Naming

With the profile still selected you will see a number of tabs on the right side of the window. In the first tab named Text you can set the initial size of the window when it opens. A good size would be 120 columns by 40 rows. You may need to adjust those settings based on the resolution of your monitor. You want your terminal to fill a good portion of your screen but not all of it. This will give plenty of room for multiple tmux and or vim panes later on in the book.

One other change you may or may not want is to disable the scrollbar display. By default the Terminal shows an orange scrollbar in the Terminal window. I find it a bit distracting to see and scrolling works just as well without the visible scrollbar. To turn it off click the Scrolling tab for the profile and uncheck the Show scrollbar setting.

Gnome Terminal Scrollbar Setting
Gnome Terminal Scrollbar Setting

If you downloaded the Anonymous Pro font or have your own font that you would like to use in the terminal you will need to use the gnome-tweaks tool again. You have to set a system wide monospace font. It cannot be done at a terminal profile level. Close the Terminal Preferences window by clicking the Close button in the lower right and then run the tweaks program again.

$ gnome-tweaks

Select the Fonts tab in the left section of the window. Then click the button next to the Monospace setting. Choose the font you wish to use and adjust the size at the bottom of the window then click the Select button in the title bar to finish the selection.

Gnome Tweaks Monospace Font Setting
Gnome Tweaks Monospace Font Setting

That’s all for the Ubuntu Terminal settings. Close and reopen the Terminal application to see the changes you made.

macOS

The Terminal application that comes with macOS does not support True Color Mode, so you will need to install a different Terminal. Fortunately iTerm2 is a very good, free and feature laden option. You can find information, documentation and installation instructions at the iTerm2 website.

iTerm2 User Interface
iTerm2 User Interface

Preferences

Once you have iTerm2 installed open the application and then click the iTerm2 menu and select Preferences…. Select Profiles at the top of the Preferences window. We will create a new default profile that will be used for all new terminal windows.

iTerm2 Gerneral Profile Settings
iTerm2 Gerneral Profile Settings

Click the + button at the bottom of the list to create a new profile. Name it anything you like, for the book it will be called Development. You do not need to change any other settings on the General pane, though you can pick a shortcut key if you like.

Next click the Text section. Here we will change the font that this terminal profile will use. Click the Change Font button and find Anonymous Pro in the font family list box and select it. The default font size is 12, but that is a little small for me so I generally change it to 14. Pick a font size that is comfortable for you. Close the Fonts dialog and ensure that the font name and size next to the Change Font button reflect your changes.

iTerm2 Font Settings
iTerm2 Font Settings

Now click the Window section. We will increase the size of new terminal windows. The default of 80 columns by 25 rows looks dinky on todays high resolution monitors. Find the Settings for New Windows section and change the Columns value to 160 and the Rows value to 40. You might need to play around with those values depending on the resolution of your monitor. You want your terminal to fill a good portion of your screen but not all of it. This will give plenty of room for multiple tmux and or vim panes later on in the book.

iTerm2 Window Size Settings
iTerm2 Window Size Settings

Finally, at the bottom of the Profile list click the Other Actions… drop down control. From the menu select Set as Default. This will make your new profile the default for all new terminal windows.

One other iTerm2 preference you might want to change right away is the Quit iTerm2 setting. By default, every time you quit iTerm2 it will display a dialog asking if you want to quit. This can get old fast. If you would like to turn off that prompt open the iTerm2 Preferences window and make sure the General pane is selected. Then uncheck the check box next to the Confirm “Quit iTerm2 (⌘Q)” if windows open setting. Close the Preferences window and now when you exit iTerm2 it will no longer prompt you.

Windows

The Windows Terminal situation is a bit limited. WSL uses the built in Windows Terminal by default. It is possible to use a third party Terminal on Windows, but getting it to work with WSL is a bit tricky and beyond the scope of this book.

Everything works in the Windows Terminal, except for true color. As I go through the instructions in the following chapters I will point out some changes that you should make to the configuration files for WSL. Mainly just excluding the true color settings.

If you installed the Anonymous Pro font, or have a font that you prefer you can set it by right clicking on the WSL Terminal window title and choosing Properties from the menu. Click on the Font tab in the Properties dialog. You can choose your desired font and font size here.

Windows Terminal Font Settings
Windows Terminal Font Settings

You should also click on the Layout tab and increase the default size of the Terminal Window. Change the values in the Window Size section of the dialog. I have mine set to a width of 120 and height of 40. Depending on your screen resolution you might want to make yours larger or smaller. You can see a relative size in the Window Preview.

Windows Terminal Size Settings
Windows Terminal Size Settings

Text Editing

Vim isn’t going to be covered for a little while yet, and there is going to be a bit of text editing done between now and then. If you have a text editor installed already that you are used to using feel free to stick with it for now.

If you would like to start getting used to working exclusively in the Terminal you can use nano for now. Nano is a very simple Terminal based text editor that is available by default on both macOS and Ubuntu.

You can start nano by just entering the nano command at the prompt.

$ nano

You can also supply the path to a file name to open.

$ nano ~/test.txt
nano Text Editor User Interface
nano Text Editor User Interface

If the file doesn’t already exist the editor window will be empty, and you will see a [ New File ] notification at the bottom of the screen. Making any changes in the file and saving it will create the file.

Once nano is open you can use the arrow keys to move around, enter and delete text as you normally would in any editor.

There is a list of commands at the bottom of the nano window. The commands all start with the caret (^) character. That signifies the <Ctrl> key. The write command, ^o, means to press the <Ctrl> key and the o key at the same time.

When you are done editing a file save your changes with <Ctrl-o> and exit nano with <Ctrl-x>.

Dotfiles Project

Now we can create the Git repository that will hold the various configuration files that will be added as we go along setting up our development environment. Just the skeleton of the project will be created here so it will be ready for the next chapter.

Open up your Terminal of choice and make sure you are in your home directory. Then create the Git repository.

$ cd ~
  $ git init dotfiles
  $ cd dotfiles

With the Git repository created we can start setting up the structure of the project and get it pushed up to a remote repository.

First create a scripts directory. This directory will be added to the system path in the next chapter and will be the home for a script that will be used to setup this environment on a new machine. (I will be covering the setup.sh script in Appendix One.) You can also add your own scripts here to make them available when you work in the terminal. (The scripts directory will be added to the shell path in the next chapter.)

$ mkdir scripts
  $ touch scripts/setup.sh

You should also create a README.md file at the root of your project. This will document your dotfiles project so you won’t forget how to install and get everything working in the future.

$ touch README.md

Just to get a little bit of info in the readme file enter the following:

~/dotfiles/README.md
  # dotfiles
  
  My personal Z Shell, tmux and Vim configuration files.

Now stage these files and commit them in Git.

$ git add -A
  $ git commit -m "Initial dotfiles project commit."

If you are using a Git hosting service such as Github or Butbucket you should create a new Repository at that service, name it dotfiles, and follow the instructions for pushing the initial commit to the remote repository.

$ git remote add origin [your repository url]
  $ git push origin master

That is all we need for now. This project will grow a little bit in each of the coming chapters as we setup and configure the development environment.

Summary

There have been a lot of details covered in this chapter. You have installed Git and a Terminal that will be your home for writing code. You have tweaked your keyboard layout slightly to make the Control key much easier to work with. You became acquainted with the nano text editor. Finally, you have created the base dotfiles project that will hold all of your configuration options for all of the packages that we will cover in the coming chapters.

You are probably raring to get going with the actual development environment and the next chapter covers a very important piece of that environment, the Shell. Take a break if you like and then dive into the next chapter and Z Shell!