Perk up your VPS and terminal with Zsh and more
One major complaint from those newer to hosting websites via a VPS, versus something more rudimentary like shared hosting, is that the terminal feels daunting and user-unfriendly. That’s an understandable response, but once you spend some time at the Linux terminal, the unease fades quickly.
Like most things with Linux, the terminal is highly customizable. With a few switches and some additional tools, you can create a terminal experience that not only feels more user-friendly, but is also far more pleasant to use.
Warning: This blog post presents one (opinionated) way to improve the terminal experience on a VPS—if you have a different route, I’d love to hear about it in the comments! I’m probably missing out on plenty of awesomeness. I’m also aware of other shells like Fish, and that Oh-My-Zsh is found to be excessive by many, but this is just one pathway to finding what works best for you.
Pick a good terminal emulator to work with
A good command line experience on your VPS will only ever be as good as the terminal emulator you use to access it. Choosing a good one, and one that you like, is fundamental to this whole exercise.
To be clear, I’m talking about the program, running on your own computer, that you use to
ssh into your VPS. There are dozens of such programs, and it’s ultimately up to personal preference.
OS X comes with Terminal.app built-in, although many like iTerm2 as an alternative.
Linux users rejoice—there are so many options, for so many different kinds of users. Your distribution will come with one emulator (probably GNOME Terminal), but you can also try Guake, rxvt, st, Terminator, and more.
For those who use multiple operating systems and want consistency, a few cross-platform options are available as well, such as Hyper and Alacritty. You can even get Terminus on your Android/iOS devices.
Don't have a VPS yet? Want a new server to play around in?
Our prices are 90% lower than the competition. Save $2,574 with 16GB RAM! But hurry, pricing expires soon.
Install Zsh on your VPS
The default Unix shell that comes with Ubuntu, Debian, CentOS, and others—Bash—is very capable, but doesn’t come with a number of features that allow for user customization, whether the end goal is beauty or functionality. Even though Zsh was first released in 1990, it still modernized many of Bash’s original approaches.
First and foremost, Zsh comes with built-in, sophisticated autocompletion, which improves the overall terminal experience immediately. For example, you can type in
ls, and then hit
Tab, and you’ll see a list of possible completions. Hit
Tab again and you’ll see that you’ve selected the first item on the list. Now you can use
Tab again to cycle through the options, or get more fine-grained control with your arrow keys. Find the autocomplete you need, hit
Enter, and you’re off.
Zsh will auto autocorrect your mistakes as well, so if you slip a key and type in
dokcer, ZSH will ask:
correct 'dokcer' to 'docker' [nyae]?. Cool stuff.
Zsh is also famous for its customization, whether that’s altering the look of the prompt—that
$ that you see all over the terminal—or how certain operations run.
Zsh can be installed with a single command on most Linux distributions:
$ sudo apt-get install zsh # Ubuntu/Debian $ sudo yum install zsh # CentOS
Once installed, you need to switch from the default Bash shell to Zsh. You can do that whenever you want by invoking it on-demand:
You’ll ultimately want to make the conversion permanent. The following will do exactly that:
$ chsh -s $(which zsh)
You’ll need to log out and log back into your VPS in order to see the change. Type
exit and then use
ssh again to re-connect to your VPS. You’ll find that
zsh is now your default shell, which you can confirm by invoking
echo $SHELL. The result should read like
Upgrade Zsh with ‘Oh My Zsh’
Oh-My-Zsh is a massive open source effort to create beautiful themes and powerful plugins for the Zsh shell. It helps manage your ZSH configuration (a bevy of options kept in the
~/.zshrc file), and makes it even easier to customize your terminal experience.
Installation is offered via a single-line command:
$ sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
The installer adds a
~/.oh-my-zsh/ directory, and edits the heck out of the default
When it’s finished, your terminal prompt will look a little different. That’s the
robbyrussell theme from Oh-My-Zsh, and if it’s not to your liking, you can choose from the dozens of themes that come packaged with Oh-My-Zsh. All you need to do is open up your
.zshrc file and change the
ZSH_THEME variable to the theme of your choosing.
Afer that, you’ll need to “source” your
.zshrc file again by typing
source .zshrc into your terminal.
Personally, I’m a huge fan of the Spaceship ZSH theme, which not only looks beautiful, but allows for some sophisticated customization for how Oh-My-Zsh’s plugins work. Speaking of plugins…
Do you do a lot of work in
docker? Oh-My-Zsh comes with plugins that make autocompletion of arguments a snap. For example, if you type in
git c followed by
Tab, you’ll see a list of options from which to choose. If you type
docker k followed by
Tab, it will autocomplete to
To enable plugins, add them to your
.zshrc file under the
plugins=(git docker rails ruby)
You can add as many of the bundled plugins as you’d like!
Discover more Zsh awesomeness
I’ve discussed some of the fundamental features of Zsh, such as autocompletion with
Tab, but there’s far, far more out there.
Here are a few of my favorites.
Quickly moving up directories: If you’ve just dove deep into a bunch of subdirectories and now want to crawl your way out, typing
cd three or four times, or typing
cd ../../.., you can use
cd ..... You can even shorten that to
cd required! Add or subtract more dots as needed.
Move around without
.... to move up a few directories is possible because Zsh understands that you’re trying to move from one directory to another. You can do the same to move anywhere in your system.
You can jump to home with
$ ~, or move to the
/etc directory, for example, by just typing
$ /etc. It’s just a few keystrokes of difference, but if you’re working in the terminal enough, that adds up quick.
Fuzzy matching of directories/files
With Zsh, you can be somewhat… imprecise about where you’re going and what you’re trying to do, but only because Zsh is smart enough to correct you.
I have the
.md file for this very blog post in the
~/work/ssdnodes/drafts/blog_termtools/ directory. If I want to jump there quickly using Zsh’s fuzzy matching capabilities, I could use the following:
Zsh will automatically expand the command, and will even autocorrect my capital
drafts. Cool, huh?
Save your .zshrc file, use it everywhere
The best terminal experience is one that’s consistent between multiple computers and multiple VPSs. Consistency means you can hit the ground running using all of your favorite tricks, personal configurations, and Zsh shortcuts.
Because Zsh stashes all of your configurations inside one
.zshrc file, it’s fully portable. If you want to bring the terminal experience you’ve just created here to another machine, simply install Oh-My-Zsh and copy over your
Add in tmux for good measure
Why have one terminal when you can have two… or dozens? That’s what
tmux, a “terminal multiplexer,” allows you to do.
ssh into a VPS, you have one shell to work with—that might be enough for most administrative jobs, but sometimes you need a second prompt to do something else while the first is occupied. You could open up another terminal on your machine and
ssh in a second time, but
tmux allows you, essentially, create another terminal “tab.” Better yet, you can detach from your shell and return to it at a later time, ensuring you don’t lose any work if your
ssh connection is dropped.
We have a comprehensive look into tmux that you should check out. Install it, understand the shortcuts, and get to multiplexing!
In reality, there’s no end to how you might want to customize and improve your own terminal experience. With Zsh in hand, the options are pretty limitless.
Lots of developers even put their
.zshrc files (among others, all known as dotfiles) onto places like GitHub for others to borrow from as needed, creating a wide open source community for very particular shell configurations. Check out the thoughtbot, skwp, and holman dotfile repositories for some inspiration and a place to start.
These dotfiles can be excellent resources, but be wary of just copy-pasting them into your own
.zshrc file—they might change functions you’re familiar with, or break your workflows entirely. It’s usually best to work your way through them slowly (hopefully they’re well documented) and take what you need.
Have other tips, tricks, or tools for making your terminal experience even better? Let me know in the comments—I’d love to explore them, and maybe yet add them to this very guide.