I am using Amazon EC2 instance and when I run bundle install
as ec2-user, it works fine but when I try the same as root user, it gives error.
bash: bundle: command not found
There is bundler gem exist when I run gem list
for both users. I have installed ruby-devel rubygems ruby-libs as root user. Can anyone please help me understand this issue? I have searched and read for hours.
echo $PATH of both users are as below.
root: /sbin:/bin:/usr/sbin:/usr/bin:/opt/aws/bin
ec2-user: /usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/aws/bin:/home/ec2-user/bin
I added /usr/local/bin
and /usr/local/sbin
to secure_path in /etc/sudoers
sudo visudo
Then change this line:
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin
Changed this to
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
Explanation:
Gems were installed at /usr/local path and without adding this in secure_path, root user cannot run scripts from there. You can check your gems path by running gem env
in shell.
I also had another issue. I installed gems as ec2-user using bundle and default rubygems path in Amazon Linux installed them only for ec2-user, something I did not like so I installed ruby and rubygems from source which has path to installed them at central location under /usr/local. I know it is not recommended by many but I like it this way. By the way, I tried to find a way to change rubygems path but I could not.
Try sudo -i -u $USER bundle install
where $USER
is the correct username so : sudo -i -u root bundle install
If this does not work, consider giving a try to the rbenv-sudo plugin .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.