Mac Terminal can't run most commands after restarting it

假装没事ソ 提交于 2020-01-03 17:46:05

问题


I am using a mac. I have a customised terminal zsh, and it was fine for a while. But after I restarted my computer, it started to behave differently:

  • The terminal stopped running commands such as rake or rails.
  • I have already created applications using rails, but using a rails command like rails -v now gives me this:

    Rails is not currently installed on this system. To get the latest version, simply type:
    
  • The terminal used to display a tilde ~ instead of my username and that has also stopped. It now displays the full username:

    Gustaves-MacBook-Air% $ sudo gem install rails
    

I have no idea why it doesn't work, and why restarting the computer would break it, even though I've done it before.

I can't even re-download rails:

$ sudo gem install rails
zsh: command not found: $

because I have customised my terminal long ago following an online setup.


回答1:


Here is how I fixed this problem, through other people's help:

First I deleted the broken files using

rm -rf ~/.oh-my-zsh
rm ~/.zshrc

Then I ran the following command to re-download zsh

sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

Finally, I opened the hidden .zshrc file with text editor to add the plugins i needed

plugins=(
  git
  bundler
  dotenv
  osx
  rake
  rbenv
  ruby
)

After restarting the terminal, everything was working again




回答2:


Try resetting zsh:

exec /bin/zsh

or

exec /usr/bin/zsh



回答3:


I believe that your Ruby environment for the directory you're in hasn't loaded properly (hence the missing Rails). It also appears your ZSH environment hasn't loaded properly (the missing ~ is a clue). Why this is, I can't be sure but I'll add some things you can do to help in the meantime.

Use Bundler with binstubs and a path

I sandbox my projects by installing all the gems into the project directory using the following command:

bundle install --binstubs --path=vendor.noindex

That will put things like rails into bin and gems under vendor.noindex. The "noindex" part stops Spotlight from indexing that directory, a real irritation for me!

Make sure ZSH is your default shell

The command for this is:

chsh -s $(which zsh)

To see what the current default is run echo $0.

Check your ~/.zshrc is in good order

If your prompt doesn't look right then perhaps the file is in bad shape or didn't load properly. Check the instructions for Oh My Zshell.

Check your PATH isn't being mangled

Your PATH looks like it's missing the front, as it begins with a colon. Check any zsh plugins you've added are working (maybe remove them all to start with and add them back in one by one).

I also use a ~/.zshenv and a helper to get paths set up correctly, maybe it will help you. I add this to my ~/.zshenv.

if [ -x /usr/local/libexec/path_helper.rb ]; then
  PATH=$(/usr/local/libexec/path_helper.rb -p "")
  DYLD_FALLBACK_FRAMEWORK_PATH=$(/usr/local/libexec/path_helper.rb --dyld "")
  C_INCLUDE_PATH=$(/usr/local/libexec/path_helper.rb -c "")
  MANPATH=$(/usr/local/libexec/path_helper.rb -m "")
fi
export PATH
export DYLD_FALLBACK_FRAMEWORK_PATH
export C_INCLUDE_PATH
export MANPATH

Hope that helps.



来源:https://stackoverflow.com/questions/53667737/mac-terminal-cant-run-most-commands-after-restarting-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!