When you work as a developer, you work with hundreds of different applications, modules, files, and packages, and they all come in many versions depending on the platform you’re using. Managing all of these packages can be very complicated when working on multiple different computers with different operating systems, for example, I use linux on a desktop computer and on the macbook pro the macOS. Every Linux version comes with some package manager that can install and upgrade our packages and usually each will install another version of the same package that can create different problems. Also, upgrading the package to the latest version may be problematic and create some other operating system compatibility problem.
There are few ways to solve those headaches and one of them is using LinuxBrew package manager. If you used Homebrew for MacOS you will be familiar with LinuxBrew which is it’s fork for Linux. One of great things about LinuxBrew is that you can install it in your home directory and that it doesn’t need root access to your system.
The same package manager can be used on both your Linux server and your Mac laptop. Installing a modern version of glibc and gcc in your home directory on an old distribution of Linux takes five minutes.
You can install LinuxBrew for every user independently and have different packages for every of them.
- Can install software to a home directory and so does not require sudo
- Install software not packaged by the native distribution
- Install up-to-date versions of software when the native distribution is old
- Use the same package manager to manage both your Mac and Linux machines
Installation and Setup
There are two ways of installing LinuxBrew on your Linux machine.
The first way is to use installation script provided by developers, it’s much faster and easier but I found it less reliable. Also it doesn’t provide you with much choice to tweak installation process further.
The second way is to install it manually from GitHub repository. It’s my favorite way of installation. It always works and I can choose where I want to place LinuxBrew files and other packages.
Debian or Ubuntu
sudo apt-get install build-essential curl file git python-setuptools
Fedora, CentOS or Red Hat
sudo yum groupinstall 'Development Tools' && sudo yum install curl file git python-setuptools
Clone from GitHub
Now when we have dependencies installed, we can clone LinuxBrew GitHub files in our home directory ~/.linuxbrew.
git clone https://github.com/Linuxbrew/brew.git ~/.linuxbrew
We have our LinuxBrew files in ~/.linuxbrew directory but our system still doesn’t know for it. If you try and enter brew command in your terminal you will get error. That’s why we need to show our system where LinuxBrew is located, we need to export PATH variable. We can use nano editor to open and edit .bashrc file in our home directory, enter in your terminal:
At the end of your .bashrc file add this part of code:
PATH="$HOME/.linuxbrew/bin:$PATH" export MANPATH="$(brew --prefix)/share/man:$MANPATH" export INFOPATH="$(brew --prefix)/share/info:$INFOPATH"
Save your file CTRL+O in nano and confirm changes. To load new PATH variable you need to restart your terminal or just enter this command:
Now if you enter brew command in your terminal you should get response with examples.
Update and upgrade
Before you start anything you should check for updates of package definitions and upgrade if available. You can do it like this:
brew update && brew upgrade
Those are two commands we chained with && and they will be executed one after another. LinuxBrew will also upgrade already installed packages to latest version available with brew upgrade command.
Search for package
You can easily search through available packages by using brew search command. If you want to install JDK (Java Development Kit) you can first search for it to get list of available packages and different versions.
brew search jdk ==> Searching local taps... jdk jdk@7 jdk@8 ==> Searching taps on GitHub... caskroom/cask/java-jdk-javadoc caskroom/cask/xamarin-jdk
We are getting list of available packages and different versions.
I want to install JDK 8 so lets use brew install command to do this:
brew install jdk@8
This command will install JDK 8, to check if it is installed use java -version command. All packages you install will be placed into your ~/.linuxbrew directory.
You can remove unwanted packages by using brew uninstall command. To uninstall JDK 8 we just installed:
brew uninstall jdk@8
To see full list of available commands and parameters check man:
man brewShare with your friends