Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mgbckr
Last active April 8, 2024 05:49
Show Gist options
  • Star 51 You must be signed in to star a gist
  • Fork 11 You must be signed in to fork a gist
  • Save mgbckr/b8dc6d7d228e25325b6dfaa1c4018e78 to your computer and use it in GitHub Desktop.
Save mgbckr/b8dc6d7d228e25325b6dfaa1c4018e78 to your computer and use it in GitHub Desktop.
Compiling and installing Zsh without root privileges on Stanford's Sherlock (https://sherlock.stanford.edu) for use in tmux
# Update 2023-07-20:
# I've recently switched to installing `zsh` via `conda` which is a lot less hassle.
# I added it to start automatically in `tmux` with
# `set-option -g default-shell "~/miniconda3/envs/default/bin/zsh"`
#
# # Install Zsh on Sherlock
# Installs Zsh with Oh-My-Zsh without root privileges
# on Stanford's Sherlock (https://sherlock.stanford.edu) for use in tmux
#
# ## Instructions
# 1) bash install_zsh.sh
# 2) edit .zshrc (add the path to your Zsh binary to the PATH variable, etc.)
# 3) add `set-option -g default-shell <path to zsh>/bin/zsh` to `~/.tmux.conf`
# 4) also see comments for potential further notes
#
# Elaborating on Step 2, this is what I added to my `.zshrc`:
# ```
# # Recently I got a bunch of errors out of the blue (e.g. `colors: function definition file not found`).
# To fix this I had to add this (source: https://github.com/ohmyzsh/ohmyzsh/issues/4607):
# export FPATH=/home/users/mgbckr/services/zsh/share/zsh/5.6.2-test-2/functions:$FPATH
# ZSH_DISABLE_COMPFIX=true
#
# # If you come from bash you might have to change your $PATH, so that we can find the `zsh` executable.
# export PATH=$HOME/services/zsh/bin:$HOME/bin:/usr/local/bin:$PATH
#
# # to enable sherlock commands like `module`
# source /share/software/user/open/lmod/lmod/init/bash
# ```
#
# References: https://www.drewsilcock.co.uk/compiling-zsh
#
# ## Notes:
#
# ### Man pages
#
# We are not installing the man pages. This causes Zsh's make to complain and exit with an error. Ignore this!
# If you want man pages, you should probably follow Drews instructions (https://www.drewsilcock.co.uk/compiling-zsh).
# However, when I tried there were some errors which I did not bother to look at. I got pretty far though using the
# following notes:
# * make sure to use a current gcc: `ml gcc/8.1.0`
# * use an "old" icmake; I used the one mentioned by Drew: 7.21.00 (https://gitlab.com/fbb-git/icmake/tags)
# * use an "old" yodl; I used 3.04.00 (https://gitlab.com/fbb-git/yodl/tags)
# * for icmake run the following (in addition to changing the log files):
# * ./icm_prepare /
# * ./icm_bootstrap x
# * ./icm_install strip all
# This actually got my to compile icmake correctly. For yodl latex was still missing.
#
# ### Ncruses
#
# Ncurses is not only required for compilation. If you delete it after the installation
# the the prompt will constantly break, e.g., when using any of the arrow keys :)
# Thus, it is integrated into the Zsh installation.
#
# ### Weird prompt and Oh-My-Zsh
#
# When you run Zsh after installing by this script. The shell is not able to parse the default prompt
# showing a bunch of color encodings and whatnot. I have no idea why this happens.
# Any other prompt than the default one seems to work fine.
# Using Oh-My-Zsh also fixes this issue.
#
ZSH_INSTALL_DIR=$HOME/services/zsh
# switch to tmp folder
mkdir tmp; cd tmp
# get ncurses
wget https://ftp.gnu.org/pub/gnu/ncurses/ncurses-6.1.tar.gz
tar -xf ncurses-6.1.tar.gz
cd ncurses-6.1
# Set cflags and c++ flags to compile with Position Independent Code enabled which we need for compiling zsh
export CXXFLAGS=' -fPIC'
export CFLAGS=' -fPIC'
./configure --prefix=$ZSH_INSTALL_DIR --enable-shared
make
# don't need this probably
#cd progs
#./capconvert
#cd ..
# probably don't need this
#export TERMINFO=/usr/share/terminfo
# test ncurses (only works with the above)
#./test/ncurses
make install
cd ..
# Tell environment where ncurses is
INSTALL_PATH="$ZSH_INSTALL_DIR"
export PATH=$INSTALL_PATH/bin:$PATH
export LD_LIBRARY_PATH=$INSTALL_PATH/lib:$LD_LIBRARY_PATH
export CFLAGS=-I$INSTALL_PATH/include
export CPPFLAGS="-I$INSTALL_PATH/include" LDFLAGS="-L$INSTALL_PATH/lib"
# Zsh
# Get zsh
git clone https://github.com/zsh-users/zsh.git
# Move into root zsh source directory
cd zsh
# Produce config.h.in, needed to produce config.status from ./configure
autoheader
# Produce the configure file from aclocal.m4 and configure.ac
autoconf
# Produce Makefile and config.h via config.status
./configure --prefix=$ZSH_INSTALL_DIR --enable-shared
make
make install
cd ..
# oh-my-zsh
# clone repository into local dotfiles
git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
# copy template file into home directory
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
cd ..
# delete tmp folder
#rm -rf tmp
@maximz
Copy link

maximz commented May 27, 2020

this is fantastic, thanks.

@mgbckr
Copy link
Author

mgbckr commented May 27, 2020

👍 😄 I am glad it helped.

@maximz
Copy link

maximz commented May 27, 2020

Btw @mgbckr did you get the module command to be available in zsh on sherlock? Looks like I can source /etc/profile.d/z99_srcc.sh (though it throws some errors) but maybe there's a cleaner way. Thanks again.

@mgbckr
Copy link
Author

mgbckr commented May 27, 2020

No, I also use source to add Sherlock commands like module. I added the corresponding source statement to my ~/.zshrc.

I am actually using source /share/software/user/open/lmod/lmod/init/bash but I feel like remembering that I was missing some commands with that. I would have to double check though.

@maximz
Copy link

maximz commented May 27, 2020

Thanks for the help. That's exactly the script I should have been sourcing! May be worth adding to the gist.

One other minor detail that may help others, probably similar to what you've done: I appended the following to my .bashrc to complete the zsh setup:

export PATH="/path/to/zsh/bin:$PATH"
[ -z "$PS1" ] && exec zsh -l

(Edited so scp still works -- scp would break if you don't check whether your shell is interactive.)

@mgbckr
Copy link
Author

mgbckr commented Jun 8, 2020

Hi, thanks for the hint. I added a bunch of notes to the script :)

@dlmgary
Copy link

dlmgary commented Aug 6, 2020

Beautiful. 👍

@evelynyang94
Copy link

Thanks a lot! This is brilliant!

@SmirnGreg
Copy link

Hi! Thanks a lot. I have used it to install zsh on a machine I use. I had a minor issue, though.

# Get zsh
git clone git://github.com/zsh-users/zsh.git

Cloning via SSH is only possible if SSH keys are configured on github.com. Maybe you could change it to HTTPS as git clone https://github.com/zsh-users/zsh.git, which does not require any prior setup?

@mgbckr
Copy link
Author

mgbckr commented Dec 22, 2020

Hi Grigorii, good call. Changed :)

@kaustubhcs
Copy link

This is fantastic!

@mgbckr
Copy link
Author

mgbckr commented May 19, 2021

Glad it helps :)

@Dragonizedpizza
Copy link

Can I use this on Ubuntu? If yes, how do I do it in /usr/bin

@Dragonizedpizza
Copy link

...I want to install it with root privileges. Ubuntu's current zsh version on apt is very old (5.4).

@Syzygianinfern0
Copy link

Syzygianinfern0 commented Mar 8, 2022

Does anyone get any error like this on the make install step of zsh?

make[1]: Entering directory '/home/user/tmp/zsh/Doc'
/bin/sh ../mkinstalldirs /home/user/services/zsh/share/man/man1
for file in zsh.1 zshbuiltins.1 zshcalsys.1 zshcompctl.1 zshcompwid.1 zshcompsys.1 zshcontrib.1 zshexpn.1 zshmisc.1 zshmodules.1 zshoptions.1 zshparam.1 zshroadmap.1 zshtcpsys.1 zshzftpsys.1 zshzle.1 zshall.1; do \
    test -s $file || exit 1; \
    /usr/bin/install -c -m 644 $file /home/user/services/zsh/share/man/man1/`echo $file | sed 's|zsh|zsh|'` || exit 1; \
done
make[1]: *** [Makefile:475: install.man] Error 1
make[1]: Leaving directory '/home/user/tmp/zsh/Doc'
make: *** [Makefile:222: install.man] Error 2

Edit: A quick and dirty dirty fix

I guess the error was something related to the zsh man pages and I don't really care about them. So I just removed the lines which were associated in building them like this:

# install/uninstall just the man pages
install.man uninstall.man:
-    @cd Doc && $(MAKE) $(MAKEDEFS) $@	
+    true 

# install/uninstall just the runhelp files
install.runhelp uninstall.runhelp:
-    @cd Doc && $(MAKE) $(MAKEDEFS) $@
+    true

@sahiljhawar
Copy link

@Syzygianinfern0 Where did you made these changes?

@Syzygianinfern0
Copy link

@sahiljhawar afair its in the Makefile.in

@Syzygianinfern0
Copy link

Basically you get to skip building the man pages

@sahiljhawar
Copy link

Ahh okay. But even after doing this, when do zsh, following error occurs

/home/enlil/jhawar/.oh-my-zsh/oh-my-zsh.sh:122: compinit: function definition file not found
/home/enlil/jhawar/.oh-my-zsh/oh-my-zsh.sh:145: zrecompile: function definition file not found
/home/enlil/jhawar/.oh-my-zsh/lib/completion.zsh:78: bashcompinit: function definition file not found
 compdef: command not found
/home/enlil/jhawar/.oh-my-zsh/lib/termsupport.zsh:108: add-zsh-hook: function definition file not found
/home/enlil/jhawar/.oh-my-zsh/lib/termsupport.zsh:109: add-zsh-hook: function definition file not found
/home/enlil/jhawar/.oh-my-zsh/lib/theme-and-appearance.zsh:2: colors: function definition file not found
 compdef: command not found
 compdef: command not found
 compdef: command not found
 compdef: command not found
/home/enlil/jhawar/.oh-my-zsh/plugins/git/git.plugin.zsh:153: is-at-least: function definition file not found
 compdef: command not found
 compdef: command not found
 compdef: command not found
 compdef: command not found
 compdef: command not found
 compdef: command not found
/home/enlil/jhawar/.oh-my-zsh/plugins/git/git.plugin.zsh:215: is-at-least: function definition file not found
/home/enlil/jhawar/.oh-my-zsh/plugins/git/git.plugin.zsh:254: is-at-least: function definition file not found
/home/enlil/jhawar/.oh-my-zsh/plugins/git/git.plugin.zsh:302: is-at-least: function definition file not found

@sahiljhawar
Copy link

sahiljhawar commented Jul 14, 2023

in the $HOME/tmp/zsh/Makefile and $HOME/tmp/zsh/Makefile.in

@Syzygianinfern0 did you asked the question or I hallucinated?

@Syzygianinfern0
Copy link

Ahh okay. But even after doing this, when do zsh, following error occurs

/home/enlil/jhawar/.oh-my-zsh/oh-my-zsh.sh:122: compinit: function definition file not found
/home/enlil/jhawar/.oh-my-zsh/oh-my-zsh.sh:145: zrecompile: function definition file not found
/home/enlil/jhawar/.oh-my-zsh/lib/completion.zsh:78: bashcompinit: function definition file not found
 compdef: command not found
/home/enlil/jhawar/.oh-my-zsh/lib/termsupport.zsh:108: add-zsh-hook: function definition file not found
/home/enlil/jhawar/.oh-my-zsh/lib/termsupport.zsh:109: add-zsh-hook: function definition file not found
/home/enlil/jhawar/.oh-my-zsh/lib/theme-and-appearance.zsh:2: colors: function definition file not found
 compdef: command not found
 compdef: command not found
 compdef: command not found
 compdef: command not found
/home/enlil/jhawar/.oh-my-zsh/plugins/git/git.plugin.zsh:153: is-at-least: function definition file not found
 compdef: command not found
 compdef: command not found
 compdef: command not found
 compdef: command not found
 compdef: command not found
 compdef: command not found
/home/enlil/jhawar/.oh-my-zsh/plugins/git/git.plugin.zsh:215: is-at-least: function definition file not found
/home/enlil/jhawar/.oh-my-zsh/plugins/git/git.plugin.zsh:254: is-at-least: function definition file not found
/home/enlil/jhawar/.oh-my-zsh/plugins/git/git.plugin.zsh:302: is-at-least: function definition file not found

I don't remember getting this error. Does zsh work without oh-my-zsh?

@sahiljhawar
Copy link

No

@mgbckr
Copy link
Author

mgbckr commented Jul 20, 2023

A quick note:

I recently switched to installing zsh via conda, which is a lot less hassle.
I added it to start automatically in tmux with set-option -g default-shell "~/miniconda3/envs/default/bin/zsh".

@sahiljhawar
Copy link

I installed zsh using conda in a new enviroment. But OMZ still give the above error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment