Issue
I am trying to run the command: su - <username> -c RAILS_ENV=production rake assets:precompile
as root, even though ruby, rvm and all gems were installed as an another user. Thats because, I have lost access to the computer from which I could login to the server with that username.
So when I run the above command, I get the following error:
rake aborted!
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, Rakefile.rb)
I am in the rails app directory when executing the above command. ls
gives me:
Gemfile README.rdoc app config db log public test vendor
Gemfile.lock Rakefile bin config.ru lib migrate solr tmp
Similarily if I do: su - <username> -c "bundle"
, I get the error: Could not locate Gemfile
.
I have read posts on SO such as Link #1, Link #2, Link #3, Link #4, but none have been able to resolve the issue.
Please if someone knows the method to resolve this and can give me an answer that will be a huge relief.
Solution
Since you installed rvm as another user, all your gems and such will be placed in that user's home directory, as will the actual version of ruby you're using. In order to get everything working as root, you'd either need to reinstall rvm system-wide and set things up that way, or you could try getting RVM running as root.
When you install rvm, it adds the following lines to the user's ~/.bash_profile
, so you could try adding this to root's:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting
Here, you'd need to substitute $HOME
for /home/username
, where username is the user that has rvm installed. Otherwise, it would default to the home directory of the currently logged in user, which would be /root
.
Another idea, you say you lost access to the computer you could log in as that user from. But, if you can log in as root, you can change anything in the system. Assuming it's an ssh key issue, why not just add your current computer's ~/.ssh/id_rsa.pub
to the user's ~/.ssh/authorized_keys
as root, and then log in and execute commands as that user as you originally intended?
Answered By - take