Skip to content

Instantly share code, notes, and snippets.

@arthurdapaz
Created April 16, 2019 22:59
Show Gist options
  • Save arthurdapaz/af11b5cd1a1a7f18e18afcbbee3f7176 to your computer and use it in GitHub Desktop.
Save arthurdapaz/af11b5cd1a1a7f18e18afcbbee3f7176 to your computer and use it in GitHub Desktop.
Script to install bash without brew or wget on MacOS
#!/usr/bin/env bash
# Install Bash 5.0 (MacOS)
VERSION="5.0"
BASH_SHORT="bash-$VERSION"
BASH_SRC="$BASH_SHORT.tar.gz"
BASH_URL="https://ftp.gnu.org/gnu/bash"
BASH_PREFIX="/usr/local"
BASH_PATH="$BASH_PREFIX/bin/bash"
# initial setup
cd ~/
curl -Ok $BASH_URL/$BASH_SRC
tar -zxvf $BASH_SRC
mv $BASH_SHORT .bash && cd .bash/
./configure --prefix=$BASH_PREFIX && make && sudo make install
printf "\nInstalled bash'es:\n"
which -a bash
printf "\nWhitelisting the new bash...\n"
grep -q $BASH_PATH /private/etc/shells || echo $BASH_PATH | sudo tee -a /private/etc/shells
printf "\nSetting default shell:\n"
chsh -s $BASH_PATH
sudo chsh -s $BASH_PATH
printf "\nCreating uninstaller..."
touch bash_uninstall
cat > bash_uninstall <<EOF
#!/usr/bin/env bash
cd ~/.bash
sudo make uninstall clean
printf "\nCleaning whitelist...\n"
sed /$(sed 's:/:\\/:g' <<< $BASH_PATH)/d /private/etc/shells
printf "\nRemoving leftovers...\n"
rm -rf ~/.bash && cd ~/
printf "\nSetting old bash back...\n"
chsh -s /bin/bash
sudo chsh -s /bin/bash
printf "\nInstalled bash'es:\n"
which -a bash
printf "\nOld bash is back!\n"
EOF
chmod +x bash_uninstall
printf "\nCleaning source: "
cd ~/ && rm -vf $BASH_SRC
printf "\n\nExit terminal and reopen to start using $BASH_SHORT\nTo uninstall it and revert to old:\n~/.bash/bash_uninstall\n"
exit
@madisonpeople
Copy link

I like your post, your script & an uninstall option, Thank you.
May ask for little more?
Advice, I want to learn a new language, I thought I would start with a simple terminal Lang for my computer.
I have a mid 2010 imac.

pauzs-iMac:~ pauz$ help
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin17)
These shell commands are defined internally. Type help' to see this list. Type help name' to find out more about the function name'. Use info bash' to find out more about the shell in general.
Use man -k' or info' to find out more about commands not in this list.

I think I succeeded in updating to this a month or two ago here at github from what came installed?
Today as I read up on where to start, many say that version 3.2.57 is old from 2007 and to update for lots of reasons.
Any tips? perhaps I should practice more for a month so I can use your script correctly.
Do you have a place/book you refer beginners too?
(I'm a 54 yr old lay user, I plan to practice at least 1/2 hr day or I will get no where-obviously)

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