rubyshellscriptingrubygemszsh

zsh script command not finding ruby gem


I'm trying to write a simple .zsh script to start my webservers upon computer boot.

This works well:

#!/bin/zsh
cd /Users/me/Sites/Vue/mysite && npm run dev &

But this doesn't work:

#!/bin/zsh
cd /Users/me/Sites/Ruby/mysite && rackup &

This is the error message:

❯ ./myscript.zsh
Resolving dependencies...
Could not find proper version of rack (2.2.4) in any of the sources
Run `bundle install` to install missing gems.

Obviously, when I run the command in the terminal window directly, it cds and executes rackup without a problem.


Solution

  • It seems that either the rackup executable that is in your $PATH when you open a new terminal is not the same one that's in your path when you run your boot script, or else there are other aspects of the environment that are different in the two different scenarios.

    You can test this by adding echo $PATH and env at the top of script and examining what is printed for each scenario.

    If using the wrong $PATH is the issue, one quick and easy solution would be to call rackup using the full path instead, like so :

    # replace /path/to with actual path
    
    cd /Users/me/Sites/Ruby/mysite && /path/to/rackup &