HomeBrew and package management for rootless Linux environments

Original link: http://ponder.work/2023/05/28/homebrew-as-non-root-package-manager/

For maintenance and security reasons, some public Linux servers generally only provide users with normal privileges.
The permissions of ordinary users are enough for daily use, but it is difficult to configure your own development environment and install some packages you need.

If you compile and install software from source code, the maintenance of dependencies is too complicated, and the version of the initial compilation tool chain may not meet the requirements, such as the version of gcc is too low.
If you apply for sudo permission or request to update the system or install docker, it will be difficult to define the responsibilities later, and the operation and maintenance and administrators will generally not agree.

Therefore, the optimal solution is for users who need to maintain their own tool chain and environment in their personal directory. The solution below is built around HomeBrew.

Install miniconda to resolve pre-dependencies

If your system is relatively new, you can try安装HomeBrew directly.

Based on the content discussed above, public servers generally have the problem of low system version, it is not uncommon for centos7 or centos6, and the version of libraries such as glibc is also very low.

Installing HomeBrew has two strong dependencies, git and curl, and the versions of the dependencies are relatively high, and the version of centos7 cannot be satisfied.
In addition, since many Brew software needs to be compiled from source code, gcc and a good network environment are also indispensable.

Fortunately, miniconda can solve the above problems. miniconda only provides dependencies for HomeBrew installation, which can be deleted later.

Configure conda source (optional): Create a new .condarc with the following content

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 channels :
- defaults
show_channel_urls : true
default_channels :
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels :
conda -forge : https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
msys2 : https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
bioconda : https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
menpo : https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch : https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch -lts : https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
simpleitk : https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

Download and install miniconda

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 # download
# If the server's built-in certificate has expired, add the --no-check-certificate condition to skip certificate verification
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && chmod +x Miniconda3-latest-Linux-x86_64.sh

# install
./Miniconda3-latest-Linux-x86_64.sh -b -p ~/miniconda3
source ~/miniconda3/etc/profile.d/conda.sh

# Install required packages
conda install -y gcc_linux-64 gxx_linux-64 curl git

# Link gcc, these links can be deleted after the HomeBrew installation is complete
cd ~/miniconda3/bin/
ln -s x86_64-conda_cos6-linux-gnu-gcc gcc
ln -s x86_64-conda_cos6-linux-gnu-cpp c++
ln -s gcc cc

Configure installation environment variables

These environment variables can also be configured in files such as bashrc to make them permanent

 1
2
3
4
5
6
7
8
9
10
 # Set up curl and git, optional
export HOMEBREW_CURL_PATH=~/miniconda3/bin/curl
export HOMEBREW_GIT_PATH=~/miniconda3/bin/git

# Set the installation source as Tsinghua source. If the network is unblocked, it can be ignored, and Tsinghua source may also be 403
export HOMEBREW_INSTALL_FROM_API=1
export HOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"

Install HomeBrew

HomeBrew needs to be installed manually since you don’t have root privileges.
Since it is a manual installation, the location is different from the default installation location, and many precompiled packages cannot be used, and must be compiled from source code, so network and machine performance and patience are very important.

 1
2
3
4
5
6
7
8
9
10
 # Download, you can also use Tsinghua source https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
git clone https://github.com/Homebrew/brew ~/.homebrew

# install
eval "$(~/.homebrew/bin/brew shellenv)"
brew update --force --quiet
chmod -R go-w "$(brew --prefix)/share/zsh"

# Automatically load brew
echo 'eval "$(~/.homebrew/bin/brew shellenv)"' >> ~/.bashrc

refer to

This article is transferred from: http://ponder.work/2023/05/28/homebrew-as-non-root-package-manager/
This site is only for collection, and the copyright belongs to the original author.