According to the official docs you just download a pre-compiled binary but this would leave things like man documentation and autocompletion not working.
- 193,181
- 53
- 473
- 722
- 349
- 1
- 2
- 8
-
If you've answered your question, you might want to accept anyone of the answers. – Anwar Sep 07 '16 at 05:58
4 Answers
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
- 339
- 4
- 13
-
-
@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
-
1ppa:cpick/hub has not been updated in years, and provides a very old version of hub – Mike Slinn Apr 13 '19 at 16:42
-
More up to date info on how to add a repo that contains hub can be found here: https://github.com/github/hub/issues/718 – Thomas David Baker Jun 22 '19 at 22:05
Updated answer
As PatKilg pointed out in the comment, the Hub maintainers now discourage using the snap.
Original answer
Hub is available as a snap now. https://snapcraft.io/hub
You can install it with sudo snap install --classic hub.
- 199
- 2
- 6
-
1
-
1Installing via snap is officially not recommended by the hub maintainers. See README at https://github.com/github/hub – PatKilg Oct 18 '20 at 15:28
Install Hub
Download Hub from Github
Extract it. I've extracted it to
Apps/directory in my home and renamed it tohub-linux. So, in my setup, the complete path to thebinfolder is/home/anwar/Apps/hub-linux/binNow open the
~/.bashrcfile and add the hub binary path to the$PATHenvironment 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.
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
- 349
- 1
- 2
- 8
-
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
-
Thanks, the bash version works for me. One note, if one want to use other versions of hub, just replace 2.2.9 with 2.14.2 (or other version number) in the script. – Huanfa Chen Jun 02 '22 at 15:26