Daniel's Tech Blog

Cloud Computing, Cloud Native & Kubernetes

Install Homebrew for Linux in Azure Cloud Shell

As macOS user you properly know Homebrew the package manager and you might know that you can install it also on Linux.

The Azure Cloud Shell is based on an Ubuntu image, but has some special requirements where to store data that should be persisted throughout your sessions.

-> https://docs.microsoft.com/en-us/azure/cloud-shell/persisting-shell-storage#how-cloud-shell-storage-works

Therefore, we cannot use the standard install command /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" as this installs Homebrew under /home/linuxbrew/.linuxbrew in Azure Cloud Shell. This path is not persisted as it is not part of your home directory.

First, clone the Linuxbrew repository into your home folder.

git clone https://github.com/Linuxbrew/install.git

Then navigate to the file install. Run code install to open the file in the editor and jump to line 24. There you change the path for the variable HOMEBREW_PREFIX_DEFAULT from /home/linuxbrew/.linuxbrew to #{ENV[“HOME”]}/.linuxbrew.

Before:
---
HOMEBREW_PREFIX_DEFAULT = "/home/linuxbrew/.linuxbrew".freeze
---
After:
---
HOMEBREW_PREFIX_DEFAULT = "#{ENV["HOME"]}/.linuxbrew".freeze
---

After hitting save, we can install Homebrew by running the command ./install.

Now, we add the path $HOME/.linuxbrew/bin to our $PATH environment variable.

export PATH=$HOME/.linuxbrew/bin:$HOME/bin:/usr/local/bin:/home/daniel/.local/bin:$PATH
export ZSH="$HOME/.oh-my-zsh"
...

As seen in the .zshrc code snippet you place the path at the first position. This ensures that executables / binaries installed via brew are the default ones. Even they already exist in the Azure Cloud Shell with another version.

Bash and Zsh are included in the Azure Cloud Shell image in version 4.3.48 and 5.1.1.

With brew and the adjustments made to .zshrc, we are now able to install the latest versions of Bash and Zsh.

From time to time run rm -rf $(brew --cache) to free up space in your Azure Cloud Shell image as you only have 5 GB of storage capacity. Except for your clouddrive folder that is bound to the limits of Azure Files.

That is all for now.

-> https://github.com/Linuxbrew/install
-> https://docs.brew.sh/Homebrew-on-Linux


Posted

in

WordPress Cookie Notice by Real Cookie Banner