If you are looking for some packages available using the popular macOS package manager HomeBrew on Amazon Linux 2023 then here are the steps to follow.
Although the default software repository of Al2023 is enough to get most of the open-source packages, still, if you think the Brew is a more user-friendly way to install software packages from source or precompiled binaries than being a Linux user you can easily get it. Furthermore, Brew also automates the process of fetching source code, resolving dependencies, configuring, compiling, and installing software.
Some key features of Homebrew or LinuxBrew include simple package installation, dependency management, version control, updates and upgrades, community contributions, and support Linux systems.
Step 1: Install Prerequisites
I am assuming that you already have access to your Amazon Linux 2023 command terminal and now you are looking for the commands to install Brew. However, before that let’s install a few things which we require before moving further.
First, run the system update:
sudo dnf update
Before installing Homebrew, ensure that your Amazon Linux instance has curl and git. You can install them using the DNF package manager:
sudo dnf install curl git --allowerasing
Step 2: Install Homebrew on Amazon Linux 2023
After downloading the Git and cURL using the previous command, we will now download the HomeBrew file directly from its GitHub repository.
First, create the directory /home/linuxbrew/ using the given command in which the -p option ensures that the command creates the directory and any parent directories that do not exist.
sudo mkdir -p /home/linuxbrew/
Next, we give the ownership of the /home/linuxbrew/ directory to the current user ($USER) using the chown command.
chown $USER: /home/linuxbrew/
Once you have given the permission, create a directory “.linuxbrew” inside /home/linuxbrew/. This directory will be used to store Homebrew-related files and binaries.
sudo mkdir /home/linuxbrew/.linuxbrew/
Now, we clone the Homebrew repository from GitHub to the created directory which is /home/linuxbrew/.linuxbrew.
git clone https://github.com/Homebrew/brew /home/linuxbrew/.linuxbrew/Homebrew
After cloning also create a “bin” directory inside /home/linuxbrew/.linuxbrew/bin. This directory will be used to store symbolic links to Homebrew binaries.
mkdir /home/linuxbrew/.linuxbrew/bin
Now create a symbolic link (brew) in the “/home/linuxbrew/.linuxbrew/bin/” directory, pointing to the Homebrew binary located at “/home/linuxbrew/.linuxbrew/Homebrew/bin/brew“. The ln -s command is used to create symbolic links.
ln -s /home/linuxbrew/.linuxbrew/Homebrew/bin/brew /home/linuxbrew/.linuxbrew/bin/brew
Step 3: Configure Homebrew Environment
After setting up the Homebrew directory, we need to configure the shell environment to set up environment variables such as PATH, MANPATH, and INFOPATH to include paths specific to Homebrew installations.
nano ~/.bashrc
Scroll to the end of the files and add the following lines:
export PATH="/home/linuxbrew/.linuxbrew/bin:$PATH"
export MANPATH="/home/linuxbrew/.linuxbrew/share/man:$MANPATH"
export INFOPATH="/home/linuxbrew/.linuxbrew//share/info:$INFOPATH"
Save the file by pressing Ctrl+O, hitting the Enter key, and exiting Ctrl+X.
Reload your shell configuration:
source ~/.bashrc
After adding it to your PATH, run the command to update Homebrew and its all installed packages to their latest versions.
brew update --force --quiet
Step 4: Verify Installation
By following the all commands given above on our Amazon Linux 2023 we will have the Homebrew installed and configured for us. Let’s confirm the same by checking its version, here is the command to do that. The output will show the version number of Homebrew.
brew --version
Step 5: HomeBrew Example Usage
Just like DNF, we can also use HomeBrew to install various packages available through its repository on our Amazon Linux 2023 instance. Here are some examples:
Syntax:
brew install package-name
For example:
MySQL:
brew install MySQL
To get Git:
brew install git
For Python:
brew install python
Node.js installation:
brew install node
PostgreSQL:
brew install PostgreSQL
Docker:
brew install docker
Uninstallation
To uninstall Homebrew from Amazon Linux 2023, we just need to delete its installation directory along with the paths we added in our .bashrc file.
Remove Homebrew Installation Directory:
rm ~/home/linuxbrew/
Remove Homebrew from PATH: Edit the Bashrc file…
nano ~/.bashrc
Now, find and delete the following lines
export PATH="/home/linuxbrew/.linuxbrew/bin:$PATH"
export MANPATH="/home/linuxbrew/.linuxbrew/share/man:$MANPATH"
export INFOPATH="/home/linuxbrew/.linuxbrew//share/info:$INFOPATH"
After saving the changes, reload your shell configuration to apply them.
source ~/.bashrc
Conclusion:
Installation Homebrew on Amazon Linux 2023 is not easy, however, if you follow each step carefully it will be on your system. It will provide an extra way to manage software packages and dependencies on your EC2 instances. If you are facing any error while setting up Brew on your Linux then let us know through the comment section.
Other Articles:
- Python’s Boto3 library Installation on Amazon Linux 2023
- Installing the Atop tool in Amazon Linux 2023 for Monitoring
- How to Add a Group in Amazon Linux 2023
- How to install Laravel on Amazon Linux 2023?
- How To Install MongoDB on Amazon Linux 2023