Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alsunseri/dbd4d9d2fee5b59a8325ecd025d3c723 to your computer and use it in GitHub Desktop.
Save alsunseri/dbd4d9d2fee5b59a8325ecd025d3c723 to your computer and use it in GitHub Desktop.
quickly install homebrew on Amazon Linux 2
#!/usr/bin/bash
# on amazon linux II my developers can not run sudo and more importantly no user has a password.
# installing linuxbrew/homebrew is a pain unless you do this:
# as root ( or sudo from the admin user )
mkdir -p /home/linuxbrew/
chown $THE_DEV_USERNAME: /home/linuxbrew/
#### root/admin work is done !!!!
# then the developer themselves can run the rest:
#
# as THE_DEV_USERNAME person
# i.e.
sudo -u $THE_DEV_USERNAME
#
mkdir /home/linuxbrew/.linuxbrew/
git clone https://github.com/Homebrew/brew /home/linuxbrew/.linuxbrew/Homebrew
mkdir /home/linuxbrew/.linuxbrew/bin
ln -s /home/linuxbrew/.linuxbrew/Homebrew/bin/brew /home/linuxbrew/.linuxbrew/bin/brew
eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)
# note -
# REMEMBER TO add line 10 to .bashrc for THE_DEV_USERNAME !
# updated and improved from Garrett S. Y. Hampton
# https://garrettsyhampton.wordpress.com/2019/10/02/how-to-install-homebrew-on-amazon-linux/
@dwiyatci
Copy link

Thanks for the script! 🙏 In my case, I'm a developer who's given full access to my own isolated machine (VM) on EC2 by my admin user, so I adapted the script:

#! /usr/bin/bash

THE_DEV_USERNAME=ec2-user

mkdir -p /home/linuxbrew/
chown $THE_DEV_USERNAME: /home/linuxbrew/

sudo -u $THE_DEV_USERNAME bash <<EOF
mkdir /home/linuxbrew/.linuxbrew/
git clone https://github.com/Homebrew/brew /home/linuxbrew/.linuxbrew/Homebrew
mkdir /home/linuxbrew/.linuxbrew/bin/
ln -s /home/linuxbrew/.linuxbrew/Homebrew/bin/brew /home/linuxbrew/.linuxbrew/bin/brew
eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)
EOF

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