{"id":1367,"date":"2018-11-10T20:47:26","date_gmt":"2018-11-10T17:47:26","guid":{"rendered":"http:\/\/kifarunix.com\/?p=1367"},"modified":"2024-03-11T21:36:32","modified_gmt":"2024-03-11T18:36:32","slug":"how-to-install-and-setup-zsh-and-oh-my-zsh-on-ubuntu-18-04","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/how-to-install-and-setup-zsh-and-oh-my-zsh-on-ubuntu-18-04\/","title":{"rendered":"How to Install and Setup ZSH and Oh-My-Zsh on Ubuntu 18.04"},"content":{"rendered":"\n<p>Welcome folks to this very tutorial on how to install and setup Zsh and Oh-my-Zsh on Ubuntu 18.04.<\/p>\n\n\n\n<p><a href=\"http:\/\/zsh.sourceforge.net\/\" target=\"_blank\" rel=\"noopener noreferrer\">Z shell<\/a> (ZSH) is a Unix shell that can be used as an interactive login shell and as well as a command interpreter for shell scripting. It incorporates features of other shells such as Bash, tcsk, ksh. Some of the features include;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Smart command TAB auto-completion<\/li>\n\n\n\n<li>Improved variable\/array handling<\/li>\n\n\n\n<li>Spelling correction<\/li>\n\n\n\n<li>Enables sharing of command history among all running shells<\/li>\n\n\n\n<li>Editing of multi-line commands in a single buffer<\/li>\n\n\n\n<li>It is highly customization<\/li>\n<\/ul>\n\n\n\n<p>Zsh configuration managed by&nbsp;a delightful, open source and community-driven framework&nbsp; called <a href=\"https:\/\/github.com\/robbyrussell\/oh-my-zsh\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>Oh My Zsh<\/strong><\/a>. Oh My Zsh comes bundled with a ton of functions, helpers, plugins and themes that can be used to spice your shell experience.<\/p>\n\n\n\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\"><h2>Table of Contents<\/h2><nav><ul><li><a href=\"#installing-zsh-and-oh-my-zsh-on-ubuntu-18-04\">Installing ZSH and Oh-My-Zsh on Ubuntu 18.04<\/a><ul><li><a href=\"#pre-requisites\">Pre-requisites<\/a><\/li><li><a href=\"#install-zsh-on-ubuntu\">Install Zsh on Ubuntu<\/a><\/li><li><a href=\"#configure-zsh\">Configure Zsh<\/a><\/li><li><a href=\"#install-oh-my-zsh\">Install Oh-my-Zsh<\/a><\/li><li><a href=\"#configuring-oh-my-zsh\">Configuring Oh-My-Zsh<\/a><\/li><li><a href=\"#theme-configuration\">Theme Configuration<\/a><\/li><li><a href=\"#enable-oh-my-zsh-plugins\">Enable Oh-My-Zsh Plugins<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"installing-zsh-and-oh-my-zsh-on-ubuntu-18-04\">Installing ZSH and Oh-My-Zsh on Ubuntu 18.04<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"pre-requisites\">Pre-requisites<\/h3>\n\n\n\n<p>As a pre-requisite, ensure that the following tools are installed; <code>git, wget, curl<\/code><\/p>\n\n\n\n<p>You can install them by running the command below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo apt-get install wget curl git<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"install-zsh-on-ubuntu\">Install Zsh on Ubuntu<\/h3>\n\n\n\n<p>Zsh is available on Ubuntu repositories by default. You can therefore install it using the package manager as shown below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo apt install zsh<\/pre>\n\n\n\n<p>Zsh can also be installed from the source by following instructions outlined in INSTALL file in the source code directory. You can get the source code from the locations defined in the <a href=\"http:\/\/zsh.sourceforge.net\/FAQ\/zshfaq01.html#16\" target=\"_blank\" rel=\"noopener noreferrer\">Zsh FAQ<\/a>.<\/p>\n\n\n\n<p>Once the installation is done, you can verify the Zsh version by running the following command;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">zsh --version\nzsh 5.4.2 (x86_64-ubuntu-linux-gnu)<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"configure-zsh\">Configure Zsh<\/h3>\n\n\n\n<p>Now that Zsh in installed, make it your default shell by running the command below;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>chsh -s $(which zsh)<\/code><\/pre>\n\n\n\n<p>This will the default shell for the current user. If run <code>sudo chsh -s $(which zsh)<\/code> it will change the default shell for root.<\/p>\n\n\n\n<p>If Zsh is not listed in <code>\/etc\/shells<\/code> or if you dont have privileges to run <code>chsh<\/code> command, then changing your default shell to Zsh will not work. In that case, you may try the solutions suggested <a href=\"https:\/\/unix.stackexchange.com\/questions\/136423\/making-zsh-default-shell-without-root-access\/136426\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a> or <a href=\"http:\/\/zsh.sourceforge.net\/FAQ\/zshfaq01.html#16\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>.<\/p>\n\n\n\n<p>Now, logout and login again in order to use Zsh as your new default shell. You can also just exit the current terminal and open a new one. You will be prompted to set your Zsh start up files. See the screenshot below;<\/p>\n\n\n\n<figure class=\"wp-block-image alignnone\"><a href=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2018\/11\/zsh-newuser-install.png\"><img loading=\"lazy\" decoding=\"async\" width=\"731\" height=\"432\" src=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2018\/11\/zsh-newuser-install.png\" alt=\"zsh-newuser-install\" class=\"wp-image-1368\" title=\"\"><\/a><figcaption class=\"wp-element-caption\">zsh-newuser-install<\/figcaption><\/figure>\n\n\n\n<p>Press option 2 to populate your <code>~\/.zshrc<\/code> with the default configuration settings.<\/p>\n\n\n\n<p>You can verify that Zsh is actually your default shell by running the following command;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">echo $SHELL\n<strong>\/usr\/bin\/zsh<\/strong><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"install-oh-my-zsh\">Install Oh-my-Zsh<\/h3>\n\n\n\n<p>In order to manage Zsh, you need to install oh-my-zsh framework. You can use either <code>curl<\/code> or <code>wget<\/code> commands to install Oh-my-zsh framework as shown below;<\/p>\n\n\n\n<div class=\"highlight highlight-source-shell\">\n<pre>sh -c <span class=\"pl-s\"><span class=\"pl-pds\">\"<\/span><span class=\"pl-pds\">$(<\/span>curl -fsSL https:\/\/raw.githubusercontent.com\/robbyrussell\/oh-my-zsh\/master\/tools\/install.sh<span class=\"pl-pds\">)<\/span><span class=\"pl-pds\">\"<\/span><\/span><\/pre>\n<\/div>\n\n\n\n<p>or<\/p>\n\n\n\n<div class=\"highlight highlight-source-shell\">\n<pre>sh -c <span class=\"pl-s\"><span class=\"pl-pds\">\"<\/span><span class=\"pl-pds\">$(<\/span>wget https:\/\/raw.githubusercontent.com\/robbyrussell\/oh-my-zsh\/master\/tools\/install.sh -O -<span class=\"pl-pds\">)<\/span><span class=\"pl-pds\">\"<\/span><\/span><\/pre>\n<\/div>\n\n\n\n<p>When you run either of the commands above, you should see the output as shown in the screenshot below;<\/p>\n\n\n\n<figure class=\"wp-block-image alignnone\"><a href=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2018\/11\/oh-my-zsh.png\"><img loading=\"lazy\" decoding=\"async\" width=\"730\" height=\"467\" src=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2018\/11\/oh-my-zsh.png\" alt=\"How to Install and Setup ZSH and Oh-My-Zsh on Ubuntu 18.04\" class=\"wp-image-1369\" title=\"\"><\/a><figcaption class=\"wp-element-caption\">oh-my-zsh<\/figcaption><\/figure>\n\n\n\n<p>Now that the Zsh management framework is installed, proceed to customize your shell so that you can get the &#8220;oh-my-zsh&#8221; feeling.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"configuring-oh-my-zsh\">Configuring Oh-My-Zsh<\/h3>\n\n\n\n<p>The main configuration file for Zsh is located under <code>$HOME\/.zshrc<\/code> while the Oh-my-Zsh configuration files are located under <code>$HOME\/.oh-my-zsh\/<\/code> directory.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"theme-configuration\">Theme Configuration<\/h3>\n\n\n\n<p>Oh-my-Zsh framework comes bundled with several themes located under <code>$HOME\/.oh-my-zsh\/themes\/<\/code>. Zsh uses the <code>robbyrussel<\/code> theme.<\/p>\n\n\n\n<p>In order to change the default theme, you need to ediit the <code>~\/.zshrc<\/code> configuration file and change the value of <code>ZSH_THEME=<\/code> to your preferred theme. In this case, we are going to use the <code>agnoster<\/code> theme that is available under oh-my-zsh themes as <code>agnoster.zsh-theme<\/code>.<\/p>\n\n\n\n<p>To test if agnoster theme is compatible with your terminal and font support, run the command below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">echo \"\\ue0b0 \\u00b1 \\ue0a0 \\u27a6 \\u2718 \\u26a1 \\u2699\"\n<strong>\ue0b0 \u00b1 \ue0a0 \u27a6 \u2718 \u26a1 \u2699<\/strong><\/pre>\n\n\n\n<p>Edit the Zsh configuration to set the theme<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">vim .zshrc<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>...<\/strong>\n# Set name of the theme to load --- if set to \"random\", it will\n# load a random theme each time oh-my-zsh is loaded, in which case,\n# to know which specific one was loaded, run: echo $RANDOM_THEME\n# See https:\/\/github.com\/robbyrussell\/oh-my-zsh\/wiki\/Themes\n<strong>#ZSH_THEME=\"robbyrussell\" &lt; comment out this line\nZSH_THEME=\"agnoster\"\n<\/strong>...<\/pre>\n\n\n\n<p>Once you have made the changes, save and exit the file and reload the <code>~\/.zshrc<\/code> to effect the changes.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>source ~\/.zshrc<\/code><\/pre>\n\n\n\n<p>You will immediately see the changes as you can see below.<\/p>\n\n\n\n<figure class=\"wp-block-image alignnone\"><a href=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2018\/11\/new-zsh-theme.png\"><img loading=\"lazy\" decoding=\"async\" width=\"724\" height=\"103\" src=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2018\/11\/new-zsh-theme.png\" alt=\"\" class=\"wp-image-1370\" title=\"\"><\/a><figcaption class=\"wp-element-caption\">new-zsh-theme<\/figcaption><\/figure>\n\n\n\n<p>You can also set Zsh to choose the themes randomly by setting the value of <code>ZSH_THEME=<\/code> to random as in <code>ZSH_THEME=\"random\"<\/code>. With this feature, you can also define a number of random themes to choose from for example;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ZSH_THEME_RANDOM_CANDIDATES=(\n  <span class=\"pl-s\"><span class=\"pl-pds\">\"<\/span>risto<span class=\"pl-pds\">\"<\/span><\/span>\n  <span class=\"pl-s\"><span class=\"pl-pds\">\"<\/span>agnoster<span class=\"pl-pds\">\"<\/span><\/span>\n)<\/pre>\n\n\n\n<p>Install Powerline fonts to spice up your fonts;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo apt install fonts-powerline<\/pre>\n\n\n\n<p>Close the terminal and open a new one again. The prompt shape should have changed.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2018\/11\/fancy-prompt-shape.png\"><img loading=\"lazy\" decoding=\"async\" width=\"722\" height=\"167\" src=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2018\/11\/fancy-prompt-shape.png\" alt=\"fancy-prompt-shape\" class=\"wp-image-1371\" title=\"\"><\/a><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"enable-oh-my-zsh-plugins\">Enable Oh-My-Zsh Plugins<\/h3>\n\n\n\n<p>Just like it is loaded with themes, oh-my-zsh has a lot of plugins located under <code class=\"markup--code markup--p-code\">~\/.oh-my-zsh\/plugins<\/code>. You can also define your custom plugins under <code class=\"markup--code markup--p-code\">~\/.oh-my-zsh\/custom\/plugins<\/code>.&nbsp; To enable a plugin, edit the <code>~\/.zshrc<\/code> and add a plugin under the <code><strong>plugins=<\/strong><\/code> parameter.<\/p>\n\n\n\n<p>For example to enable <strong>sudo<\/strong> plugin that allows you to enter sudo automatically in case you forgot to type it when running a long command that requires to sudo privileges to excute by pressing <strong>ESC <\/strong>twice.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># Which plugins would you like to load?\n# Standard plugins can be found in ~\/.oh-my-zsh\/plugins\/*\n# Custom plugins may be added to ~\/.oh-my-zsh\/custom\/plugins\/\n# Example format: plugins=(rails git textmate ruby lighthouse)\n<strong># Add wisely, as too many plugins slow down shell startup.<\/strong>\nplugins=(\n  git\n  <strong>sudo<\/strong>\n)<\/pre>\n\n\n\n<p>Once you are done, save the file and source the ~\/.zshrc configuration file.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2018\/11\/zsh-sudo-plugin.gif\"><img loading=\"lazy\" decoding=\"async\" width=\"735\" height=\"55\" src=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2018\/11\/zsh-sudo-plugin.gif\" alt=\"zsh-sudo-plugin\" class=\"wp-image-1372\" title=\"\"><\/a><\/figure>\n\n\n\n<p>To enable colored man pages plugins, add the plugin&#8217;s name to the list and source the ~\/.zshrc.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">plugins=(\n  git\n<strong>  sudo\n  colored-man-pages<\/strong>\n)<\/pre>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2018\/11\/zsh-colored-man-pages.png\"><img loading=\"lazy\" decoding=\"async\" width=\"725\" height=\"429\" src=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2018\/11\/zsh-colored-man-pages.png\" alt=\"zsh-colored-man-pages\" class=\"wp-image-1373\" title=\"\"><\/a><\/figure>\n\n\n\n<p>To enable syntax highlighting custom plugin that can help identify a typo or something similar in your command, install<a href=\"https:\/\/github.com\/zsh-users\/zsh-syntax-highlighting#zsh-syntax-highlighting-\" target=\"_blank\" rel=\"noopener noreferrer\"> zsh-syntax-highlighting<\/a> as shown below;<\/p>\n\n\n\n<p>Clone the zsh-syntax-highlighting repository into oh-my-zsh&#8217;s custom plugins directory:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git clone https:\/\/github.com\/zsh-users\/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~\/.oh-my-zsh\/custom}\/plugins\/zsh-syntax-highlighting<\/code><\/pre>\n\n\n\n<p>Activate the plugin by adding it to list of plugins in ~\/.zshrc<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">plugins=(\n  git\n  <strong>sudo<\/strong>\n  <strong>colored-man-pages<\/strong>\n  <strong>zsh-syntax-highlighting<\/strong>\n)<\/pre>\n\n\n\n<p>Source <code>~\/.zshrc<\/code> for the changes to take effect.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>source ~\/.zshrc<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2018\/11\/zsh-syntax-highlight.png\"><img loading=\"lazy\" decoding=\"async\" width=\"724\" height=\"54\" src=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2018\/11\/zsh-syntax-highlight.png\" alt=\"zsh-syntax-highlight\" class=\"wp-image-1375\" title=\"\"><\/a><\/figure>\n\n\n\n<p>Another awesome plugin is the zsh-autosuggestions plugin which suggests commands as you type, based on command history.<\/p>\n\n\n\n<p>Clone the<a href=\"https:\/\/github.com\/zsh-users\/zsh-syntax-highlighting#zsh-syntax-highlighting-\" target=\"_blank\" rel=\"noopener noreferrer\">&nbsp;<\/a>zsh-autosuggestions repository into oh-my-zsh&#8217;s customs plugins directory:<\/p>\n\n\n\n<div class=\"highlight highlight-source-shell\">\n<pre>git clone https:\/\/github.com\/zsh-users\/zsh-autosuggestions <span class=\"pl-smi\">${ZSH_CUSTOM<span class=\"pl-k\">:-<\/span>~<span class=\"pl-k\">\/<\/span>.oh-my-zsh<span class=\"pl-k\">\/<\/span>custom}<\/span>\/plugins\/zsh-autosuggestions<\/pre>\n<\/div>\n\n\n\n<p>Activate the plugin by adding it to list of plugins in ~\/.zshrc<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">plugins=(\n  git\n  <strong>sudo<\/strong>\n  <strong>colored-man-pages<\/strong>\n  <strong>zsh-syntax-highlighting\n  zsh-autosuggestions\n<\/strong>)<\/pre>\n\n\n\n<p>Source <code>~\/.zshrc<\/code> for the changes to take effect.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>source ~\/.zshrc<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2018\/11\/zsh-autosuggestions.gif\"><img loading=\"lazy\" decoding=\"async\" width=\"735\" height=\"239\" src=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2018\/11\/zsh-autosuggestions.gif\" alt=\"zsh-autosuggestions\" class=\"wp-image-1376\" title=\"\"><\/a><\/figure>\n\n\n\n<p>If for some reasons, you got a theme issue whereby suggestions text color matches with the background color such that you can&#8217;t see the suggestions, you can always adjust the value of <code>ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE<\/code> variable. Check the <a href=\"https:\/\/github.com\/zsh-users\/zsh-autosuggestions#configuration\" target=\"_blank\" rel=\"noopener noreferrer\">configuration<\/a>.<\/p>\n\n\n\n<p>Well, Zsh is very customizable.<\/p>\n\n\n\n<p>You can customize it the way you want. Feel free to explore this awesome tool. We hope this was informative. Oh-my-Zsh&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Welcome folks to this very tutorial on how to install and setup Zsh and Oh-my-Zsh on Ubuntu 18.04. Z shell (ZSH) is a Unix shell<\/p>\n","protected":false},"author":1,"featured_media":17716,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[121,64],"tags":[7001,7002,232],"class_list":["post-1367","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","category-ubuntu-18-04","tag-install-zsh-ubuntu-18-04","tag-oh-my-zsh-ubuntu-18-04","tag-zsh-oh-my-zsh","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50","resize-featured-image"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/1367"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=1367"}],"version-history":[{"count":8,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/1367\/revisions"}],"predecessor-version":[{"id":21066,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/1367\/revisions\/21066"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/17716"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=1367"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=1367"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=1367"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}