M1芯片Mac安装gcc

M1芯片Mac安装gcc

本文用来记录gcc的安装流程,初次安装时踩了不少的坑。

2022-09-13 更新补充了国内镜像安装方法

虽然大多数软件对M1芯片进行了适配,但为了保险起见,可以在Does it ARM网站查询需要安装的软件是否已适配。

1. 官方安装方法

本方法在终端使用Homebrew进行,因Homebrew和gcc的安装都需要翻墙,所以需要使用代理,如果没有代理的话请跳过本节。

优点:官方最新版本,稳定可靠

缺点:需要代理,速度可能很慢

1.1 在终端中声明代理

打开代理软件查看端口号,如127.0.0.1:7070,在终端使用以下命令开启代理

export http_proxy="http://127.0.0.1:7070"
export https_proxy="http://127.0.0.1:7070"

1.2 Homebrew的安装

Homebrew官网查询得到安装命令如下(如果没有开启代理,本部分会报错连接失败)

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

输入登陆密码等待安装,如果电脑里没有CLT(Command Line Tools),本部分会自动安装。全部安装完成后,终端提示如下

Warning: /opt/homebrew/bin is not in your PATH.
  Instructions on how to configure your shell for Homebrew
  can be found in the 'Next steps' section below.
==> Installation successful!

==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
Read the analytics documentation (and how to opt-out) here:
  https://docs.brew.sh/Analytics
No analytics data has been sent yet (nor will any be during this install run).

==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
  https://github.com/Homebrew/brew#donations

==> Next steps:
- Run these two commands in your terminal to add Homebrew to your PATH:
    echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/****/.zprofile
    eval "$(/opt/homebrew/bin/brew shellenv)"
- Run brew help to get started
- Further documentation:
    https://docs.brew.sh

按照Next steps提示添加环境路径,命令如下(将>>后的路径替换为终端显示的路径)

echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/****/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"

1.3 使用brew安装gcc

Homebrew界面输入gcc进入gcc介绍界面,得到安装命令如下

brew install gcc

等待安装结束即可。

1.4 关闭终端代理

全部安装结束后,使用以下命令关闭代理

unset http_proxy
unset https_proxy

2. 国内镜像安装

本方法安装步骤类似上一个,区别在于安装过程均使用了国内镜像链接。

2.1 Homebrew的安装

CunKai/HomebrewCN提供了国内镜像版的Homebrew安装脚本,使用如下命令安装

/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

注:此镜像详细信息可自行前往仓库链接查看。

按照终端提示安装。

2.2 使用brew安装gcc

因为2.1节安装结束时已经设置了国内镜像,所以本节也不再需要代理,安装命令如下

brew install gcc

等待安装结束即可。

猜你喜欢

转载自blog.csdn.net/qq_36529483/article/details/124210245