1

On Mac OS my CI server's build agent runs as root. I have messed with the ruby version on by defaul ruby -v reports version 2.0, while after eval "$(rbenv init -)" is being executed, I get a desired 2.4.

If I were to set the eval "$(rbenv init -)" to execute each time I login to shell, I would just add it to my ~/.bash_profile.

But I assume the commands from bash_profile get executed when I actually ssh as user. How can I make sure the ruby corrector command gets executed with the system start for root?

Maxim V. Pavlov
  • 663
  • 3
  • 11
  • 29

2 Answers2

0

You can use a cron job that will run a process once at reboot.

root's crontab entry would look something like this:

@reboot       $HOME/bin/startup.sh

Use crontab -e to add the entry. You would add your ruby commands into your startup.sh file.

Run man 5 crontab for more details and options.

jftuga
  • 5,731
  • 4
  • 42
  • 51
0

I don't use rbenv, but my understanding is that the init step modifies the environment of the current shell to allow rbenv to control ruby commands (e.g. by adding the rbenv shims directory to the PATH environment variable. Each process has its own environment, so running rbenv init during system startup would affect just that process that it ran in, not the entire system.

What you need to do is run eval "$(rbenv init -)" for each new shell that you want managed by rbenv. If you want tasks run by your CI server to us rbenv, that means you need to add this to whatever initialization process those tasks use. My guess would be that adding eval "$(rbenv init -)" to the root account's ~/.bash_profile and/or ~/.bashrc, but without knowing exactly how the server works, I can't say for certain.

Gordon Davisson
  • 11,216
  • 4
  • 28
  • 33