簡體   English   中英

“zsh:找不到命令:”運行Ruby命令時

[英]"zsh: command not found:" when running Ruby commands

我仍然可以使用像 ls 或 pwd 這樣的核心命令,但無法識別與 Ruby 相關的某些命令。 不確定這是否適用於其他語言,但我似乎對 npm 或類似問題沒有任何問題。

如果有幫助,我也在使用 MacOS Catalina 版本 10.15.7

run `bundle update --bundler`
zsh: command not found: run

我不知道如何重置 zsh 或如何解決這個問題。 這是 $PATH 變量的內容:

/bin:/usr/bin:/usr/local/bin:/Users/peter/bin:/usr/local/bin:/Users/peter/bin:/usr/local/bin:/Users/peter/.rvm/gems/ruby-2.7.0/bin:/Users/peter/.rvm/gems/ruby-2.7.0@global/bin:/Users/peter/.rvm/rubies/ruby-2.7.0/bin:/Users/peter/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/peter/.rvm/bin:/Users/peter/.rvm/bin:/Users/peter/.rvm/bin

當我在終端 'vim ~/.zshrc' 中運行時,它返回以下內容

# If you come from bash you might have to change your $PATH.
export PATH=$HOME/bin:/usr/local/bin:$PATH

# Path to your oh-my-zsh installation.
export ZSH="/Users/peter/.oh-my-zsh"

# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="robbyrussell"

# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in $ZSH/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )

# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"

# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"

# Uncomment the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"

# Uncomment the following line to automatically update without prompting.
# DISABLE_UPDATE_PROMPT="true"

# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13

# Uncomment the following line if pasting URLs and other text is messed up.
# DISABLE_MAGIC_FUNCTIONS="true"

# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"

# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"

# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"

# Uncomment the following line to display red dots whilst waiting for completion.
# COMPLETION_WAITING_DOTS="true"

# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"

# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
# HIST_STAMPS="mm/dd/yyyy"

# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder

# Which plugins would you like to load?
# ZSH_CUSTOM=/path/to/new-custom-folder

# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git)

source $ZSH/oh-my-zsh.sh

# User configuration

# export MANPATH="/usr/local/man:$MANPATH"

# You may need to manually set your language environment
# export LANG=en_US.UTF-8

# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
#   export EDITOR='vim'
# else
#   export EDITOR='mvim'
# fi

# Compilation flags
# export ARCHFLAGS="-arch x86_64"

# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
# alias brewup=‘brew update; brew upgrade; brew cleanup; brew doctor’

# Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
export PATH="$PATH:$HOME/.rvm/bin"
export PATH

知道問題是什么或如何解決這個問題嗎? 如果您需要我提供更多信息,請告訴我。 我以前從未遇到過這個問題,所以不知道如何解決它。

修復SHELLPATH環境變量

要么您的 PATH 未使用正確的 SHELL 變量導出,要么您有其他一些與 PATH 相關的問題。 您可以通過多種方式解決此問題,但我會建議其中兩種方式。

反引號在您定義的 shell(例如ENV['SHELL'] )中運行命令,因此如果 zsh 不是您當前的SHELL ,或者您的 shell 不在您當前的 PATH 中,那么您將遇到問題。 在運行您的應用程序之前更新您的 PATH,或者像這樣將它添加到您的 Ruby 腳本中:

ENV['SHELL'] = '/bin/zsh'
ENV['PATH']  = [ENV['SHELL'], ENV['PATH']].join ?:

使用 Kernel#system 繞過 Shell

或者,如果您不需要捕獲標准輸出,您可以使用Kernel#system的無殼版本。 例如:

# this may not work if you're not using a system ruby
system('/path/to/bundle', 'update', '--bundler')

更多全局修復

無論您采用哪種方法,問題都可能是相同的:您沒有導出適當的SHELLPATH變量,因此您可能需要查看:

  1. 您的默認用戶外殼,例如dscl . -read ~/ UserShell dscl . -read ~/ UserShell
  2. 你的 shell 的各種啟動文件。
  3. 您的終端設置,以確保它正在啟動登錄 shell。

自己是不是在你的shell環境或IDE樹立正確的,要么,所以你需要跟蹤它。 這應該給你一個良好的開端。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM