This article is going to be about setting up a development environment on a Linux machine. Have you ever watched a coding tutorial and saw a really slick editing interface with terminal split screens and a gorgeous color scheme? Well, I am not only going to show you how to configure and setup something impressive but I will also give you the insight into how to configure it as you see fit.
All the codes mentioned here are linux terminal commands and scripts.
Mean Stack
Let’s talk about the tools stack are going to be using.
Zsh
When you open up a terminal on your machine, you are most likely going to find that you are running a Bash shell.
Bash is a nice default but we’re not here for defaults, we’re here for the best we can get and that means Zsh and all the bells and whistles that come along with it. In a nutshell, Zsh gives us a much more user friendly experience on the command line, it gives us things like better auto-completion, Vim key bindings and smart guesses when you write a command wrong. Zsh has a huge user community behind it and those smart people have added many, many customisations. We can discover those as we go.
Tmux
Tmux is a terminal multiplexor. Sounds scary right? Well, it isn’t at all. Tmux is a tool that allows you to split your terminal screen into any layout you want as well as run multiple terminal instances that are easily accessible. Tmux has become the go-to tool for some of the biggest neckbeards out there.
Vim
Vim is a text editor and if you haven’t heard of it before, well, you’re either going to love it or hate it. I do hope you will love it of course as it is an extremely versatile, customisable and powerful text editor. Now, for the sake of diversity, there is another extremely powerful text editor out there called Emacs which I would suggest you look into in your spare time and decide whether you would like to learn it. Yes, I said learn, Vim and Emacs have an extremely steep learning curve in terms of how they allow you to manipulate text. I chose Vim and I will be providing links, tips and customisations to get you where you need to be ASAP.
Here is a preview of the configuration you will end up with after configuring this mean stack
Prerequisites and Assumptions
A final comment before diving in head first is that I am making some small assumptions about your setup. They are the following:
You’re computers operating system is Debian based.
‘Debian based’ in simple terms simply means that you are using Ubuntu or a variant like Kubuntu or Lubuntu. The reason for this is that we need to be using the same package manager. Also, things are a lot more user friendly on the Ubuntu side of life.
You need some things installed to get up and running. Here are the prerequisites:
Git
You need to install git before you continue with this as git will be the primary source of packages, plugins etc. that we will be using as well as you will be using when you need to customize this. Follow the command to install git.
sudo apt-get install git
Zsh
Let’s get started. We’re going to install Zsh and kit you out with a decent terminal. Run
$ sudo apt-get install zsh
You now need to switch your default shell from whatever you have now to Zsh, Run:
$ chsh -s /bin/zsh
Close that terminal and open another and you should be looking at a lovely new Zsh prompt. We’re not done yet, remember all those customization I talked about? In order to give us a head start let’s get the community managed Zsh framework called oh-my-zsh. Let’s get it installed.
$ git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
Now that we have oh-my-zsh installed, we can customise as much as we want, let’s start by setting up our .zshrc. The .zshrc is a configuration file that is read by Zsh every time you open up a new terminal session. In other words, we can put all our customization in this file and it will be run in the background for us. Let’s create that file:
$ cd
$ touch .zshrc
Now, I am going to assume you don’t have Vim installed yet, so we can use a simple text editor that comes as default: nano.
$ nano .zshrc
You can type in text simply like with any text editor you are used to. Let’s start off by choosing a theme. Head over to oh-my-zsh themes Choose one you like (take a look at “3den”, that is the one I use), and then add the following line to your .zshrc
ZSH_THEME="3den"
Save the file by hitting Ctrl-x, and then y to confirm that you want to write to the file. Close that terminal and open another up. Brilliant, you should have a new and shiny prompt. I’ll take this moment to point out why I use the 3den theme. 3den gives me Git and Ruby information on the command line. It also gives me my current working directory and the time. The colors aren’t that bad either. Feel free to experiment with many different themes!
When you want to customise you Zsh installation, you’ll mostly be working in your .zshrc file. I am going to list some more things you might want to include in your .zshrc, feel free to test them, use them or not. Remember, this is your setup!
export TERM="xterm-256color"
setopt RM_STAR_WAIT
setopt interactivecomments
setopt CORRECT
That is enough for now, we’ll come back to add more later on. Let’s move onto Tmux.
Tmux
Grab Tmux with the following:
$ sudo apt-get install tmux
Now, Tmux can be a tricky one to figure out at the beginning, but bear with me, we will get there. I have customised my installation with the help of the very great book Tmux – Productive mouse-free development which I totally recommend. Let’s not bore you with the defaults, (although you can find them here) go ahead and create the Tmux configuration file, called .tmux.conf:
$ cd
$ nano .tmux.conf
Add the following lines:
set-option -g default-shell /bin/zsh
set -g utf8
set-window-option -g utf8 on
set -g default-terminal "screen-256color"
set -g prefix C-a
unbind C-b
set -sg escape-time 1
set-option -g base-index 1
setw -g pane-base-index 1
bind r source-file ~/.tmux.conf \; display "Reloaded!"
bind | split-window -h
bind - split-window -v
OK, Ctrl-x to save the file and then run:
$ tmux new -s myfirsttmux
Great, you see your lovely Zsh terminal, now let’s play around with those bindings you set in your .tmux.conf. Try and run them all in sequence and you will have gotten the basics of Tmux in a few minutes!
Ctrl-a |
Ctrl-a
Ctrl-a -
Ctrl-a
Ctrl-d
Ctrl-a c
Ctrl-a n
Ctrl-a d
$ tmux ls
$ tmux attach -t myfirsttmux
Ctrl-a d
$ tmux kill-session -t myfirsttmux
OK, lots of information there but you get the gist of it, You can split vertically and horizontally to your hearts content! You also have the ability to reload your Tmux configuration file whilst still in a Tmux session, so you can add a line, then hit
Ctrl-a r
You have your new configuration options loaded. Now, I mentioned I would be leaving a link to a fully customised configuration file, and I am going to keep my promise, check out my personal tmux config file . Remember, don’t just drop it all in at once, incrementally add options and test them by reloading your config!
Close Tmux, get back to a vanilla terminal and let’s move on. You’ve got the basics here.
Next, it will be Vim, the Big one. I will publish about it in my next article.