CentOS 7 下安装并配置 Homebrew

2023年 1月 4日 76.9k 0

在 CentOS 下安装包时,通常需要寻找各种源,使用 Homebrew 就没这样的烦恼。本文使用的是 CentOS 7.6,不同的系统版本可能会有差异。

1. 创建非 root 用户

Homebrew 不允许以 root 身份运行,因此需要创建一个新的用户。

  • 新建用户
  • 1
    
    adduser shaowenchen
    
  • 设置密码
  • 1
    
    passwd shaowenchen
    
  • 给新用户添加 sudo 权限
  • 编辑权限配置文件:

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

    添加如下内容

    1
    
    shaowenchen    ALL=(ALL:ALL)   ALL
    

    恢复文件权限

    1
    
    chmod -w /etc/sudoers
    

    2. 安装并配置 Homebrew

    2.1 安装必要的基础软件

    本文安装的是 Homebrew 3.0.9 , 官方文档中描述存在如下依赖:

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

    可以跳过 GCC 的检查,之后使用 Homebrew 进行安装。

    • 检查内核版本
    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
    
    • 检查 Glibc 版本
    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.
    
    • 安装基础软件
    1
    2
    
    yum groupinstall -y ‘Development Tools’
    yum install -y curl file git
    

    2.2 升级 git 和 curl

    • 升级 git 版本,不低于 2.7.0
    1
    
    yum install -y https://packages.endpoint.com/rhel/7/os/x86_64/endpoint-repo-1.7-1.x86_64.rpm
    

    升级版本

    1
    
    yum update -y git
    

    查看版本

    1
    2
    3
    
    git --version
    
    git version 2.30.1
    
    • 升级 curl 版本,不低于 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
    

    编辑源文件,开启 [city-fan.org],将 enabled 置为 1。

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

    安装依赖

    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
    

    升级版本

    1
    
    yum update -y curl
    

    查看版本

    1
    2
    3
    
    curl --version
    
    curl 7.75.0
    

    3. 安装 Homebrew

    • 切换到非 root 用户
    1
    
    su shaowenchen
    
    • 安装 Homebrew
    1
    
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    
    • 添加 brew 命令到 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
    

    直接将 .linuxbrew/bin 添加到 PATH 会导致安装新工具时,make 报错。

    • 查看版本
    1
    2
    3
    4
    
    brew  --version
    
    Homebrew 3.0.9
    Homebrew/homebrew-core (git revision 1ce004f2f0b; last commit 2021-03-28)
    
    • [可选]添加 brew 到 Zsh
    test -r ~/.zshrc && echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.zshrc
    

    4. 使用

    之前写过一篇 《Homebrew 使用》 ,介绍了一些常用的命令,这里不再重复。仅安装几个常用的软件,用于测试。

    • 安装 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
    
    • 安装 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
    
    • 安装 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. 参考

    • https://docs.brew.sh/Homebrew-on-Linux#requirements

    相关文章

    KubeSphere 部署向量数据库 Milvus 实战指南
    探索 Kubernetes 持久化存储之 Longhorn 初窥门径
    征服 Docker 镜像访问限制!KubeSphere v3.4.1 成功部署全攻略
    那些年在 Terraform 上吃到的糖和踩过的坑
    无需 Kubernetes 测试 Kubernetes 网络实现
    Kubernetes v1.31 中的移除和主要变更

    发布评论