19

According to the official docs you just download a pre-compiled binary but this would leave things like man documentation and autocompletion not working.

  • If you've answered your question, you might want to accept anyone of the answers. – Anwar Sep 7 '16 at 5:58
16

You can use this PPA to install hub as a package:

sudo add-apt-repository ppa:cpick/hub
sudo apt-get update
sudo apt-get install hub
  • Do you know if this sets up autocompletion and the git alias? – Bryce Drennan Apr 11 '18 at 18:25
  • @Bryce It looks like the latest package (2.2.9-0ubuntu0ppa1) contains a bash completion script, but no manpages or postinstall scripts. – Eugene Yarmash Apr 11 '18 at 19:40
  • ppa:cpick/hub has not been updated in years, and provides a very old version of hub – Mike Slinn Apr 13 at 16:42
  • More up to date info on how to add a repo that contains hub can be found here: github.com/github/hub/issues/718 – Thomas David Baker Jun 22 at 22:05
10

Hub is available as a snap now. https://snapcraft.io/hub

You can install it with sudo snap install --classic hub.

  • Too bad Windows Subsystem for Linux does not support snap – Mike Slinn Apr 13 at 16:41
6

Install Hub

  1. Download Hub from Github

    https://github.com/github/hub/releases

  2. Extract it. I've extracted it to Apps/ directory in my home and renamed it to hub-linux. So, in my setup, the complete path to the bin folder is /home/anwar/Apps/hub-linux/bin

  3. Now open the ~/.bashrc file and add the hub binary path to the $PATH environment variable. Adding a line like below will work.

    ### Adds Hub-linux
    export PATH="$PATH:$HOME/Apps/hub-linux/bin/"

Don't forget to to use actual path in your setup

Add the Bash Completion

To add bash completion, we need to tell bash to source the completion file came with hub-archive. The completion file is in the etc folder of the extracted hub folder. To do so,

Open the .bashrc and write there these lines

### Load Hub Linux bash completion
if [ -f $HOME/Apps/hub-linux/etc/hub.bash_completion.sh ] ; then
     . $HOME/Apps/hub-linux/etc/hub.bash_completion.sh
fi

Don't forget to replace the exact path of hub.bash_completion.sh file according to your setup

Now, You should be able to use hub bash completion

Add Hub's manpage to man database

Hub's man page actually came with the archive. It's in the share folder. To add the manpage, we need to put it in the man page directory.

To do so, Open a terminal and cd to the extracted hub archive. Assuming your current directory is in the same directory where hub's bin, share, README.md reside, use this command to copy the manpage

sudo cp -r share/ /usr/
sudo chmod 644 /usr/share/man/man1/hub.1

Now you can use hub's manual page using man hub command.

If you can't immediately use man hub, use sudo updatedb to refresh man db of the system.

2

This script should do the job on Ubuntu 16.04 with zsh.

# Install binary and documentation
wget https://github.com/github/hub/releases/download/v2.2.9/hub-linux-amd64-2.2.9.tgz
tar zvxvf hub-linux-amd64-2.2.9.tgz
sudo ./hub-linux-amd64-2.2.9/install

# Setup autocomplete for zsh:
mkdir -p ~/.zsh/completions
mv ./hub-linux-amd64-2.2.9/etc/hub.zsh_completion ~/.zsh/completions/_hub
echo "fpath=(~/.zsh/completions $fpath)" >> ~/.zshrc
echo "autoload -U compinit && compinit" >> ~/.zshrc

# add alias
echo "eval "$(hub alias -s)"" >> ~/.zshrc

# Cleanup
rm -rf hub-linux-amd64-2.2.9

Alternatively for Ubuntu 16.04 with bash:

# Install binary and documentation
wget https://github.com/github/hub/releases/download/v2.2.9/hub-linux-amd64-2.2.9.tgz
tar zvxvf hub-linux-amd64-2.2.9.tgz
sudo ./hub-linux-amd64-2.2.9/install

# Setup autocomplete for bash:
mkdir -p ~/.bash/completions
mv ./hub-linux-amd64-2.2.9/etc/hub.bash_completion.sh ~/.bash/completions/_hub
echo "if [ -f ~/.bash/completions/_hub ]; then" >> ~/.bashrc
echo "    . ~/.bash/completions/_hub" >> ~/.bashrc
echo "fi" >> ~/.bashrc

# add alias
echo "eval "$(hub alias -s)"" >> ~/.bashrc

# Cleanup
rm -rf hub-linux-amd64-2.2.9

Test installation:

hub version
  • Your bash script contains the line echo "eval "$(hub alias -s)"" >> ~/.zshrc. This looks like a zsh thing, not a bash thing? (I'm a *nix newbie, so what do I know) – Sam Axe Feb 15 '18 at 22:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.