问题
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
rakeorrails. I have already created applications using rails, but using a rails command like
rails -vnow 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