Skip to content

Instantly share code, notes, and snippets.

@PhilippeCarphin
Forked from ryin/tmux_local_install.sh
Last active March 24, 2020 12:02
Show Gist options
  • Save PhilippeCarphin/ef5536e293a47aa71bc49080341b796c to your computer and use it in GitHub Desktop.
Save PhilippeCarphin/ef5536e293a47aa71bc49080341b796c to your computer and use it in GitHub Desktop.
bash script for installing tmux without root access
#!/bin/bash
# Script for installing tmux on systems where you don't have root access.
# tmux will be installed in $HOME/.local/bin.
# It's assumed that wget and a C/C++ compiler are installed.
# However, you might want to customize the following variables:
# exit on error
set -e
# If true, the dependencies will be installed in the same place as tmux
# but if false, they will be removed after having compiled tmux since linking is
# done statically.
# This is useful if you are installing on in your home with limited space and
# won't be needing the other libraries (you can set this to false).
KEEP_DEPS=true
# Tmux version to install
TMUX_VERSION=2.3
# Version of ncurses. (5.9 had a bug in it that I couldn't figure out so I just
# took this one.)
NCURSES_VERSION=6.0
# Prefix for tmux (and ncurses and libevent in the case that KEEP_DEPS is true)
TMUX_PREFIX=$HOME/.local
# Number of threads to use for compilation
MAKE_THREADS=-j16
# If you are on an nfs filesystem, it would speed things up to set this to
# something like /home/tmp or /tmp/ since those are usualy local to the machine
# you are on.
BUILD_DIR=$HOME/tmux_tmp
# Use this one for Polytechnique Montreal computers
# BUILD_DIR=/home/tmp/tmux_tmp
# Where to install the dependant libraries if
if [[ $KEEP_DEPS == true ]]; then
DEP_PREFIX=$TMUX_PREFIX
else
DEP_PREFIX=$BUILD_DIR/build
fi
echo "TMUX_PREFIX=$TMUX_PREFIX"
echo "DEP_PREFIX=$DEP_PREFIX"
echo "TMUX_VERSION=$TMUX_VERSION"
echo "NCURSES_VERSION=$NCURSES_VERSION"
echo "MAKE_THREADS=$MAKE_THREADS"
echo -n "Is this OK? [y/n]: "
read answer
if [[ $answer != "y" ]] ; then
exit 1
fi
# create our directories
mkdir -p ${TMUX_PREFIX} $BUILD_DIR
if [[ $KEEP_DEPS != true ]]; then
mkdir -p $DEP_PREFIX
fi
pushd $BUILD_DIR
# download source files for tmux, libevent, and ncurses
# https://github.com/tmux/tmux/releases/download/2.3/tmux-2.3.tar.gz
if [ ! -e tmux-${TMUX_VERSION}.tar.gz ]; then
wget -O tmux-${TMUX_VERSION}.tar.gz https://github.com/tmux/tmux/releases/download/2.3/tmux-${TMUX_VERSION}.tar.gz
fi
if [ ! -e libevent-2.0.19-stable.tar.gz ]; then
wget https://github.com/downloads/libevent/libevent/libevent-2.0.19-stable.tar.gz
fi
if [ ! -e ncurses-${NCURSES_VERSION}.tar.gz ]; then
wget ftp://ftp.gnu.org/gnu/ncurses/ncurses-${NCURSES_VERSION}.tar.gz
fi
# extract files, configure, and compile
############
# libevent #
############
if [ ! -d libevent-2.0.19-stable ]; then
tar xvzf libevent-2.0.19-stable.tar.gz
fi
pushd libevent-2.0.19-stable
./configure --prefix=${DEP_PREFIX} --disable-shared CFLAGS="-I/usr/local/opt/openssl/include"
make ${MAKE_THREADS}
make install
popd
############
# ncurses #
############
if [ ! -d ncurses-${NCURSES_VERSION} ]; then
tar xvzf ncurses-${NCURSES_VERSION}.tar.gz
fi
pushd ncurses-${NCURSES_VERSION}
./configure --prefix=${DEP_PREFIX}
make ${MAKE_THREADS}
make install
popd
############
# tmux #
############
if [ ! -d tmux-${TMUX_VERSION} ]; then
tar xvzf tmux-${TMUX_VERSION}.tar.gz
fi
pushd tmux-${TMUX_VERSION}
./configure CFLAGS="-I${DEP_PREFIX}/include -I${DEP_PREFIX}/include/ncurses" LDFLAGS="-L${DEP_PREFIX}/lib -L${DEP_PREFIX}/include/ncurses -L${DEP_PREFIX}/include -L/usr/local/opt/openssl/lib" CPPFLAGS="-I${DEP_PREFIX}/include -I${DEP_PREFIX}/include/ncurses -I/usr/local/opt/openssl/include"
LDFLAGS="-static -L${DEP_PREFIX}/include -L${DEP_PREFIX}/include/ncurses -L${DEP_PREFIX}/lib" make ${MAKE_THREADS}
cp tmux ${TMUX_PREFIX}/bin
popd
# cleanup
rm -rf $BUILD_DIR
echo "${TMUX_PREFIX}/bin/tmux is now available. You can optionally add ${TMUX_PREFIX}/bin to your PATH."
@phil-blain
Copy link

phil-blain commented Mar 24, 2020

simpler alternative: conda install -c conda-forge tmux ;)

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