将本地binstubs添加到rbenv(找不到命令)

时间:2015-03-20 04:54:28

标签: ruby-on-rails ruby zsh rbenv

如果在Rails项目的本地bin目录中有简单的shell命令binstubs(例如,不是由gem生成或运行gem),则rbenv似乎无法执行它们。例如,@ tpope' s heroku binstubs在本地bin目录中生成名为production的binstub:

#!/bin/sh
HEROKU_APP=myapp-production HKAPP=myapp-production exec "${HEROKU_COMMAND:-heroku}" "$@"

在rbenv rehash之后,生产命令显示在~/.rbenv/shims目录中,如下所示:

#!/usr/bin/env bash
set -e
[ -n "$RBENV_DEBUG" ] && set -x

program="${0##*/}"
if [ "$program" = "ruby" ]; then
  for arg; do
    case "$arg" in
    -e* | -- ) break ;;
    */* )
      if [ -f "$arg" ]; then
        export RBENV_DIR="${arg%/*}"
        break
      fi
      ;;
    esac
  done
fi

export RBENV_ROOT="/Users/Username/.rbenv"
exec "/usr/local/Cellar/rbenv/0.4.0/libexec/rbenv" exec "$program" "$@"

因此执行which production会给你:

/Users/Username/.rbenv/shims/production

但是执行rbenv which production(或尝试运行命令)会给你:

rbenv: production: command not found

我是rbenv的新手所以也许我错过了配置步骤?

1 个答案:

答案 0 :(得分:-1)

显然,Rails项目中特定于项目的binstubs应保留在本地bin/目录之外,因为它们主要用于application scripts。因此,一种方法(即rbenv-binstubs插件使用的方法)是将本地binstub分开并用本地binstub目录覆盖rbenv填充程序(例如.bundle/bin)。因此,通过使用该插件,您可能会看到which production

的结果
/Users/Username/.rbenv/shims/production

但如果您将production binstub移至.bundle/bin,那么rbenv which production应该会产生:

{PROJECT_ROOT}/.bundle/bin/production