1

How can I avoid using sudo?

I am setting up ruby on rails on my mac ox yosemite, and along the way, I inevitably end up using 'sudo' for some of my commands. This helps me overcome the error below:

ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.

For more context, I am following this tutorial and in the section on Final Steps, I was unable to execute

rake db:create

because I needed to install pg and my user account isn't allowed to install to the system Rubygems.

I managed to overcome this problem from following the steps here (taken from this post)

Install Xcode command line tools (Apple Developer site)

brew uninstall postgresql

brew install postgresql

ARCHFLAGS="-arch x86_64" gem install pg

EXCEPT that the last step for me was

sudo ARCHFLAGS="-arch x86_64" gem install pg

Questions:

1) By using sudo - what is the implication on my computer?

2) How can I improve my set up to avoid having to use sudo?

Community
  • 1
  • 1
Roy
  • 277
  • 1
  • 5
  • 17

1 Answers1

0

Generally, you should not run commands using sudo unless you absolutely have to. I think the bigger issue here is that you are using your system Ruby which is preventing you from running some of these commands because the gem executable is owned by the root user.

I would use the Ruby Version Manager so you can have a dedicated Ruby/RubyGems executable for your specific user.

Installing RVM https://rvm.io/

gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 \curl -sSL https://get.rvm.io | bash -s stable

Keep in mind that you are more then likely still going to require escalated privileges to install things like Postgresql on your machine.

Remember, if you are running your web server as the root user, you are putting the system at a more vulnerable state. Let's say you built an app that has the ability to delete files on the server, well what if it accidentally deleted the root file system? You know, bad stuff like that.

pyRabbit
  • 803
  • 1
  • 9
  • 33