如何为一个用户设置默认的gcc版本?

如何为一个用户设置默认的gcc版本?

我与其他人共享一台服务器(Ubuntu 11.04),我是唯一一个必须使用 gcc 4-4 来编写代码的人,其余的都使用 4.5。我已经安装了 gcc 4.4,但如何将其设置为我的默认版本,而不打扰其他人?

该解决方案需要适用于 Makefile 等。

我尝试了jw013的想法,但我想我搞砸了。我创建了符号链接ln -s /usr/bin/gcc-4.4 ~/bin/gcc现在我的.bashrc不会再加载了。以下是错误消息:

Command 'lesspipe' is available in the following places
 * /bin/lesspipe
* /usr/bin/lesspipe
The command could not be located because '/usr/bin:/bin' is not included in the PATH environment variable.
lesspipe: command not found
Command 'dircolors' is available in '/usr/bin/dircolors'
The command could not be located because '/usr/bin' is not included in the PATH environment variable.
dircolors: command not found
Command 'uname' is available in '/bin/uname'
The command could not be located because '/bin' is not included in the PATH environment variable.
uname: command not found
-bash: [: =: unary operator expected
Command 'sed' is available in '/bin/sed'
The command could not be located because '/bin' is not included in the PATH environment variable.
sed: command not found
Command 'ls' is available in '/bin/ls'
The command could not be located because '/bin' is not included in the PATH environment variable.
ls: command not found

答案1

我能想到的最简单的方法是在你的目录中创建一个~/bin目录$HOME,添加一个符号链接~/bin/gcc/usr/bin/gcc-4.4gcc-4.4所在的位置,并确保~/bin在你的开头,$PATH如下所示:

export PATH=~/bin:$PATH

答案2

您可以定义一个别名。将其添加到您的~/.bashrc文件中:

alias gcc='/usr/bin/gcc-4.4'

它可以达到目的,但有点黑客。我建议使用 jw013 的符号链接方法。

答案3

请按照 3 个步骤操作

1.打开/etc/profile

2.编辑如下内容

PATH=PATH:/usr/bin:/bin
export PATH

3.$source /etc/profile

相关内容