在尝试在 Mac OSX 机器上安装某些东西的过程中,我认为我的 ~/.bash_profile 文件损坏了。我编辑了它,现在,当我打开终端时,突然间,我无法运行任何东西,甚至无法列出文件:
$ ls
-bash: ls: command not found
哦不!我尝试打开 emacs 来编辑 ~/.bash_profile,但是却无法做到:
$ emacs ~/.bash_profile
-bash: emacs: command not found
$ port install emacs
MacPorts running without privileges. You may be unable to complete certain actions (eg install).
---> Computing dependencies for emacs
MacPorts running without privileges. You may be unable to complete certain actions (eg install).
---> Fetching emacs
---> Attempting to fetch emacs-23.2.tar.gz from http://www.mirrorservice.org/sites/ftp.gnu.org/gnu/emacs
MacPorts running without privileges. You may be unable to complete certain actions (eg install).
---> Verifying checksum(s) for emacs
MacPorts running without privileges. You may be unable to complete certain actions (eg install).
---> Extracting emacs
MacPorts running without privileges. You may be unable to complete certain actions (eg install).
MacPorts running without privileges. You may be unable to complete certain actions (eg install).
---> Configuring emacs
MacPorts running without privileges. You may be unable to complete certain actions (eg install).
---> Building emacs
MacPorts running without privileges. You may be unable to complete certain actions (eg install).
---> Staging emacs into destroot
MacPorts running without privileges. You may be unable to complete certain actions (eg install).
---> Installing emacs @23.2_1
Error: Target org.macports.install returned: MacPorts requires root privileges for this action
Error: Status 1 encountered during processing.
Before reporting a bug, first run the command again with the -d flag to get complete output.
我无法使用 sudo,也无法将 Finder 更改为显示隐藏文件以从那里打开它:
$ sudo port install emacs
-bash: sudo: command not found
$ defaults write com.apple.Finder AppleShowAllFiles YES
-bash: defaults: command not found
救命!我该如何打开 ~/.bash_profile 来修复它?
答案1
使用命令的完整路径,直到修复PATH
:
/bin/ls
/path/to/emacs
ETC。
答案2
$ /usr/bin/vi ~/.bash_profile
... 假设您的文件HOME
也没有损坏。否则,cd
请转到正确的位置并进行编辑。
答案3
您可能损坏了 PATH 环境变量......
使用 finder 在 textwrangler 或类似程序中打开该文件。
答案4
运行此命令来修复你的 bash 配置文件,并将你的用户名替换为:
/usr/bin/sudo /usr/bin/nano /Users/YOURUSERNAME/.bash_profile
编辑路径时不要忘记包含:$路径到新路径字符串的末尾。应如下所示:
export PATH = "/my/new/path:$PATH"
这可能是导致您出现问题的原因。