2012-03-14 39 views
47

我最近卸載的Xcode 4.2和重新安裝的Xcode 4.3.1。命令行工具已安裝。然後我使用來自macports.org的Lion的「dmg」磁盤映像安裝MacPort。因爲,我每次使用的端口後得到sudo: port: command not found,我也跟着thisthis post創建.bash_profile文件(以前未出現),然後把它下面,但無濟於事。須藤:端口:找不到命令

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

this post

➜ ~ 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 
+1

我的Rails應用程序安裝MongoDB的時候就遇到了這個錯誤在命令行,所以我想有些人也可能會發現通過谷歌搜索,使用相同的關鍵字這個問題。我所做的只是更新XCode並從macports.org安裝MacPorts,在做此頁面上的其他任何事情之前嘗試一下。 – JGallardo 2013-08-20 17:54:23

回答

22

確保刪除在〜/ .bash_profile和〜/ .bash_login文件,這樣的.profile可以工作。這爲我工作http://johnnywey.wordpress.com/2008/04/17/fixing-bash-profile-in-os-x/

+7

我重新啓動我的終端,它又走了: -/ – Ava 2012-03-26 01:51:18

+0

什麼都沒了,你的.profile?順便說一句,你還可以在終端上使用sudo嗎?例如sudo ls? – 2012-03-26 02:41:45

+0

端口。每當我打開終端來識別端口時,我必須運行'source .profile'。 – Ava 2012-03-26 02:44:51

6

在我的馬中文,端口在/opt/local/bin/port - 嘗試將它自己輸入終端。

+0

在我的bin文件夾中,只有文件(端口是文件)'bin?s daemondo port portf portindex portmirror' – Ava 2012-03-14 00:51:36

+0

當你輸入'set | grep PATH'進入終端? – 2012-03-14 00:55:36

+0

二進制文件(標準輸入)匹配 – Ava 2012-03-14 00:56:22

14

你可以嘗試源的配置文件來更新你的環境:

$ source ~/.profile 
+1

如何獲取我的個人資料?我如何運行這個命令,只是寫在終端給'源:沒有這樣的文件或目錄:.profile' – Ava 2012-03-14 01:21:24

+0

移動到您的用戶目錄與'CD $ HOME'然後嘗試它 – Awalias 2012-03-14 02:15:39

+0

是的,我只是從那裏嘗試。 – Ava 2012-03-14 02:16:29

1

你怎麼運行which port爲您的普通用戶帳戶得到什麼?嘗試從新開的終端。將.bash_profile重命名爲.profile後再試。你能否以普通用戶的身份運行port,即使沒有參數?

+0

在上面添加了它。它被重命名。 – Ava 2012-03-19 17:41:26

1

你可以很簡單地添加一行:

source ~/.profile 

你的shell RC文件的底部 - 如果你使用bash那麼這將是你的〜/ .bash_profile中,如果你是使用的zsh這將是你的〜/ .zshrc

然後打開一個新的終端窗口並輸入端口-v你應該看到的輸出,看起來像以下:

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

希望有所幫助。

97

首先,你可能需要修改系統的PATH

sudo vi /etc/paths 

添加2個以下行:如果您剛剛安裝的MacPorts

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

重新啓動你的終端

+19

重新啓動終端的竅門!:) – damned 2013-09-18 12:17:21

+0

非常感謝,它適合我! – Joey 2013-12-23 10:17:09

+2

經過大量的.bash_profile調查後,事實證明,我只需要在安裝MacPorts後重新啓動終端。感謝您的提示。 – Ila 2014-01-21 21:31:52

3

剛運行,它應該工作

source ~/.bash_profile 
9

我找到了答案在the official website

$ vi ~/.profile 

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

現在重新啓動終端或如果您使用zsh.please添加流串到行中鍵入source !$(相當於source ~/.profile

+0

謝謝!這是最終幫助我的唯一的事情。我其實沒有'.profile',所以我創建了一個並添加了該行,並且它工作正常。 – 2016-05-22 19:15:34

+0

這應該是被接受的答案 – suyesh 2017-04-18 20:59:14

7

「導出路徑=「...」'in'〜/ .zshrc'

:/opt/local/bin:/opt/local/sbin 
+0

這對我來說是訣竅。 zsh用戶的實際解決方案。 – VorteXavier 2018-01-19 14:50:08

0

有可能是你的機器被管理的情況b y木偶左右。然後更改根.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/