修改mac默认的gcc到自己安装的gcc

我使用homebrew安装了最新版的gcc,但是gcc --version还是之前系统自带的gcc,版本是4.2.1

原来我新装的gcc的名字变成了gcc-7

➜  ~ gcc-7 --version
gcc-7 (Homebrew GCC 7.1.0) 7.1.0
Copyright (C) 2017 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.
想使用gcc-7代替系统自带gcc的方法:

vim ~/.bash_profile

在文件中追加如下几行:

alias gcc='gcc-7'
alias g++='g++-7'
alias c++='c++-7'

然后运行命令: source ~/.bash_profile

大功告成:

➜  ~ gcc-7 --version
gcc-7 (Homebrew GCC 7.1.0) 7.1.0
Copyright (C) 2017 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.




你可能感兴趣的:(环境配置)