This page looks best with JavaScript enabled

Installing and Configuring Homebrew on CentOS 7

 ·  ☕ 4 min read

When installing packages on CentOS you usually have to hunt down all sorts of repositories; with Homebrew that hassle goes away. This article uses CentOS 7.6 — other system versions may differ.

1. Create a Non-root User

Homebrew refuses to run as root, so a new user has to be created.

  1. Add a user
1
adduser shaowenchen
  1. Set a password
1
passwd shaowenchen
  1. Grant the new user sudo privileges

Edit the privilege configuration file:

1
2
chmod +w /etc/sudoers
vi /etc/sudoers

Add the following

1
shaowenchen    ALL=(ALL:ALL)   ALL

Restore the file permissions

1
chmod -w /etc/sudoers

2. Install and Configure Homebrew

2.1 Install the Necessary Base Software

This article installs Homebrew 3.0.9, and the official documentation describes the following dependencies:

* GCC 4.7.0 or newer
* Linux 2.6.32 or newer
* Glibc 2.13 or newer
* 64-bit x86_64 CPU

The GCC check can be skipped and GCC installed later with Homebrew.

  • Check the kernel version
1
2
3
uname -a

Linux myhost 3.10.0-957.21.3.el7.x86_64 #1 SMP Tue Jun 18 16:35:19 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
  • Check the Glibc version
1
2
3
4
5
6
7
ldd --version

ldd (GNU libc) 2.17
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.
  • Install the base software
1
2
yum groupinstall -y ‘Development Tools’
yum install -y curl file git

2.2 Upgrade git and curl

  • Upgrade git, no lower than 2.7.0
1
yum install -y https://packages.endpoint.com/rhel/7/os/x86_64/endpoint-repo-1.7-1.x86_64.rpm

Upgrade the version

1
yum update -y git

Check the version

1
2
3
git --version

git version 2.30.1
  • Upgrade curl, no lower than 7.41.0
1
yum install -y http://www.city-fan.org/ftp/contrib/yum-repo/city-fan.org-release-2-1.rhel7.noarch.rpm

Edit the repository file, enable [city-fan.org], and set enabled to 1.

1
2
3
4
5
vi /etc/yum.repos.d/city-fan.org.repo

[city-fan.org]
...
enabled=1

Install the dependency

1
yum install -y https://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/l/libnghttp2-1.33.0-1.1.el7.x86_64.rpm

Upgrade the version

1
yum update -y curl

Check the version

1
2
3
curl --version

curl 7.75.0

3. Install Homebrew

  • Switch to the non-root user
1
su shaowenchen
  • Install Homebrew
1
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  • Add the brew command to PATH
1
2
3
4
test -d ~/.linuxbrew && eval $(~/.linuxbrew/bin/brew shellenv)
test -d /home/linuxbrew/.linuxbrew && eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)
test -r ~/.bash_profile && echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.bash_profile
echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.profile

Adding .linuxbrew/bin directly to PATH causes make to fail when installing new tools.

  • Check the version
1
2
3
4
brew  --version

Homebrew 3.0.9
Homebrew/homebrew-core (git revision 1ce004f2f0b; last commit 2021-03-28)
  • [Optional] Add brew to Zsh
test -r ~/.zshrc && echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.zshrc

4. Usage

I previously wrote “Using Homebrew”, which covers some common commands, so I will not repeat them here. I will just install a few common tools as a test.

  • Install GCC
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
brew install gcc

==> Downloading https://linuxbrew.bintray.com/bottles/isl-0.23.x86_64_linux.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/46/46537a01a0cc82ea18528293b6bac03be7ab14b2fc3a7a28051f1b26e24f6c57?__gda__=exp=1616978202~hmac=b7727c9ae79b54bebc199a095c01e70251446ed4012bfb5900dd877e06229fd1&response-content-disposition=attachment%3Bfilename%3D%22isl-0
######################################################################## 100.0%
==> Downloading https://linuxbrew.bintray.com/bottles/gcc-10.2.0_4.x86_64_linux.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/e6/e62efea399fd03d854ff871210b941e5c3277d821e9148badceeda883f53f016?__gda__=exp=1616978204~hmac=a7e19e02629bc1c462635349fe3c01039f581e2014153c704f72e54bc2d93c35&response-content-disposition=attachment%3Bfilename%3D%22gcc-1
#################                                                         24.9%
######################################################################## 100.0%
==> Installing dependencies for gcc: isl
==> Installing gcc dependency: isl
==> Pouring isl-0.23.x86_64_linux.bottle.tar.gz
🍺  /home/linuxbrew/.linuxbrew/Cellar/isl/0.23: 73 files, 6.6MB
==> Installing gcc
==> Pouring gcc-10.2.0_4.x86_64_linux.bottle.tar.gz
Warning: The post-install step did not complete successfully
You can try again using:
  brew postinstall gcc
==> Summary
🍺  /home/linuxbrew/.linuxbrew/Cellar/gcc/10.2.0_4: 1,481 files, 264.3MB
==> No outdated dependents to upgrade!
==> Checking for dependents of upgraded formulae...
==> Reinstalling 1 broken dependent from source:
gcc
  • Install Kubectl
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
brew install kubectl

==> Downloading https://linuxbrew.bintray.com/bottles/kubernetes-cli-1.20.4_1.x86_64_linux.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/c5/c5dd394d0bd150aff18ded31f29e52ece6dcbd064ebe46e7f746891822a12eff?__gda__=exp=1616978407~hmac=13c24ddb7a7e90118b1aa8184d2c4688f719a945c4f0d033352a7cae9c845887&response-content-disposition=attachment%3Bfilename%3D%22kuber
######################################################################## 100.0%
==> Pouring kubernetes-cli-1.20.4_1.x86_64_linux.bottle.tar.gz
==> Caveats
Bash completion has been installed to:
  /home/linuxbrew/.linuxbrew/etc/bash_completion.d
==> Summary
🍺  /home/linuxbrew/.linuxbrew/Cellar/kubernetes-cli/1.20.4_1: 246 files, 40.9MB
  • Install Kind
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
brew install kind

==> Downloading https://linuxbrew.bintray.com/bottles/kind-0.10.0.x86_64_linux.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/7a/7a5595da7f271219a53cbd95a5b729c581fb3e4f8ece6d449074cbe33f10d627?__gda__=exp=1616978455~hmac=754a3789f01e3c27ebdfa1b65e51392eaeacf61f878a9d607b78d342f52c5dfa&response-content-disposition=attachment%3Bfilename%3D%22kind-
######################################################################## 100.0%
==> Pouring kind-0.10.0.x86_64_linux.bottle.tar.gz
==> Caveats
Bash completion has been installed to:
  /home/linuxbrew/.linuxbrew/etc/bash_completion.d
==> Summary
🍺  /home/linuxbrew/.linuxbrew/Cellar/kind/0.10.0: 8 files, 9.4MB

5. References


微信公众号
WRITTEN BY
微信公众号