67

我最近卸载了 Xcode 4.2 并重新安装了 Xcode 4.3.1。命令行工具已安装。然后,我使用来自 macports.org 的 Lion 的“dmg”磁盘映像安装了 MacPort。因为,sudo: port: command not found每次使用端口后,我都会按照这个这个帖子创建一个.bash_profile文件(之前不存在),然后将其放入以下但无济于事。

export PATH=$PATH:/opt/local/bin
export MANPATH=$MANPATH:/opt/local/share/man
export INFOPATH=$INFOPATH:/opt/local/share/info 

关注这个帖子

➜  ~ git:(master) ✗ rvm install 1.8.7 --with-openssl-dir=/opt/local
You requested building with '/usr/bin/gcc-4.2' but it is not in your path.
➜  ~ git:(master) ✗ vi .rvmrc 

rvm_archflags="-arch x86_64"

export CC="/usr/bin/gcc-4.2"

export CFLAGS="-O2 -arch x86_64"
export LDFLAGS="-L/opt/local/lib"
export CPPFLAGS="-I/opt/local/include"

重命名.bash_profile.profile

➜  ~ git:(master) ✗ vi .bash_profile
➜  ~ git:(master) ✗ mv .bash_profile .profile
➜  ~ git:(master) ✗ mv .profile              
usage: mv [-f | -i | -n] [-v] source target
       mv [-f | -i | -n] [-v] source ... directory
➜  ~ git:(master) ✗ mv -f .bash_profile .profile
mv: rename .bash_profile to .profile: No such file or directory
➜  ~ git:(master) ✗ port
zsh: correct 'port' to 'pr' [nyae]? n
zsh: command not found: port
➜  ~ git:(master) ✗ which port
port not found
➜  ~ git:(master) ✗ 

.profile内容:

export PATH=$PATH:/opt/local/bin
export MANPATH=$MANPATH:/opt/local/share/man
export INFOPATH=$INFOPATH:/opt/local/share/info
4

11 回答 11

134

首先,您可能需要编辑系统的 PATH

sudo vi /etc/paths

添加以下 2 行:

/opt/local/bin
/opt/local/sbin

重启你的终端

于 2013-09-17T10:23:33.537 回答
21

确保删除 ~/.bash_profile 和 ~/.bash_login 以便 .profile 可以工作。这对我有用 http://johnnywey.wordpress.com/2008/04/17/fixing-bash-profile-in-os-x/

于 2012-03-25T23:58:50.510 回答
18

您可以尝试获取您的配置文件以更新您的环境:

$ source ~/.profile
于 2012-03-14T00:51:27.253 回答
18

我在官网找到了答案

$ vi ~/.profile

# add the following line
export PATH=/opt/local/bin:/opt/local/sbin:$PATH

现在重新启动终端或类型source !$(相当于source ~/.profile

于 2015-10-04T14:29:15.463 回答
15

如果您使用 zsh。请在文件 '~/.zshrc' 中的行 'export PATH="..."' 中添加流动字符串

:/opt/local/bin:/opt/local/sbin
于 2016-03-15T13:12:17.117 回答
9

在我的机器上,端口在/opt/local/bin/port- 尝试将其输入到自己的终端中。

于 2012-03-14T00:47:33.860 回答
6

如果您刚刚安装了 macports,只需运行它就可以了

source ~/.bash_profile
于 2015-01-15T19:03:03.340 回答
1

which port作为常规用户帐户运行您能得到什么?从新打开的终端尝试一下。.bash_profile重命名为后重试.profile。即使没有参数,您也可以port作为普通用户运行吗?

于 2012-03-19T17:25:12.133 回答
1

您可以非常简单地添加以下行:

source ~/.profile

在你的 shell rc 文件的底部 - 如果你使用的是 bash,那么它就是你的 ~/.bash_profile 如果你使用的是 zsh,它就是你的 ~/.zshrc

然后打开一个新的终端窗口并输入 ports -v 你应该会看到如下输出:

~ [ port -v                                                                                                              ] 12:12 pm
MacPorts 2.1.3
Entering interactive mode... ("help" for help, "quit" to quit)
[Users/sh] > quit
Goodbye

希望有帮助。

于 2013-06-25T11:15:31.007 回答
0

可能存在您的机器由 Puppet 管理的情况。然后更改根 .profile 或 .bash_rc 文件根本不起作用。因此,您可以将以下内容添加到您的 .profile 文件中。之后,您可以使用“mydo”而不是“sudo”。它非常适合我。

function mydo() {
    echo Executing sudo with: "$1" "${@:2}"
    sudo $(which $1) "${@:2}"
}

访问我的页面:http ://www.danielkoitzsch.de/blog/2016/03/16/sudo-returns-xyz-command-not-found/

于 2016-03-16T09:04:50.677 回答
0

我将其视为端口树的问题。MacPorts在这里提供了一个解决方案,它对我有用,并不意味着改变你的环境变量。

于 2022-02-21T13:48:14.967 回答