11

Hi all I'm trying to set up a dev environment and I've been following a tutorial via; Link to tutorial

I'm not doing very well and have no real experience of terminal commands other than the most basic version control stuff. I followed the first link and when trying to run

source ~/.bash_profile

I got the error; mkdir: /usr/local/rbenv/shims: Permission denied mkdir: /usr/local/rbenv/versions: Permission denied

Now every time I load terminal the error appears.

Contents of bash_profile;

export PATH=/usr/local/rbenv/bin:$PATH
export RBENV_ROOT=/usr/local/rbenv
eval "$(rbenv init -)"

Any guidance would be greatly appreciated

Meeps
  • 387
  • 2
  • 3
  • 15
  • Can you post the contents of `.bash_profile`? – Greg Burghardt Jul 23 '15 at 13:21
  • Yep, I've added it to the question. – Meeps Jul 23 '15 at 13:23
  • 1
    It looks like the rbenv setup puts a line of shell scripting in your .bash_profile that attempts to create that directory. You could either give yourself permissions to create directories in /usr/local/rbenv, or `sudo mkdir /directories/that/need/to/be/created` once. – Greg Burghardt Jul 23 '15 at 13:29
  • Yep that's the one Greg, thanks fella. If you go ahead and answer it I'll make sure to up vote. Cheers man. – Meeps Jul 23 '15 at 13:36

4 Answers4

7

It looks like the rbenv setup puts a line of shell scripting in your .bash_profile that attempts to create that directory. You could either give yourself permissions to create directories in /usr/local/rbenv, or sudo mkdir /directories/that/need/to/be/created once.

sudo mkdir -p /usr/local/rbenv/shims
sudo mkdir -p /usr/local/rbenv/versions
Greg Burghardt
  • 17,900
  • 9
  • 49
  • 92
  • You should not create those folder yourself, `rbenv` is capable of doing it itself if it needs to. The only thing you should do is run `eval "$(rbenv init -)"` when you launch terminal using init scripts. More info in this solution : https://stackoverflow.com/a/65999645/512504 – mbritto Feb 10 '21 at 14:59
7

I was getting a permissions error when trying to install a ruby version.

It also was complaining that it couldn't complete the mkdir

In short set LDFLAGS to a blank string.

export LDFLAGS= 

Was found here: https://github.com/rbenv/rbenv/issues/766

James Trickey
  • 1,322
  • 13
  • 21
  • 2
    I had a `mkdir /usr/local/opt` error with `rbenv install` after migrating a `.bashrc` from an AMD64 Mac to an ARM64 Mac, and the install location for homebrew changed. In my `.bashrc` I had these lines in the file originally `export LDFLAGS="-L/usr/local/opt/zlib/lib -L/usr/local/opt/sqlite/lib"` and `export CPPFLAGS="-I/usr/local/opt/zlib/include -I/usr/local/opt/sqlite/include"`. When I updated them to: `export LDFLAGS="-L/opt/homebrew/opt/zlib/lib -L/opt/homebrew/opt/sqlite/lib"` and `export CPPFLAGS="-I/opt/homebrew/opt/zlib/include -I/opt/homebrew/opt/sqlite/include"` all was fixed. – spkane May 07 '22 at 03:12
  • 1
    `LDFLAGS="" rbenv install` worked for me, in case you don't want to always export blank LDFLAGS. – Chad M Nov 18 '22 at 20:59
  • on OSX, you can do `env LDFLAGS= rbenv install` – Orlando Jul 21 '23 at 19:18
4

The actual solution ;-) (without the need of changing permissions or creating directories) is to change your bash_profile (or other like .zshrc as in my case) and remove the two exports:

export PATH=/usr/local/rbenv/bin:$PATH
export RBENV_ROOT=/usr/local/rbenv

Start a new shell, to be sure, and execute your rbenv install <your_version_of_choice> and it will install without any issues.

Running eval "$(rbenv init -)" should be enough for your environment. See rbenv init explained. I also think this is safer as you rely on the install to do it's work properly.

Gems are installed without the need of root/sudo.

Ray Oei
  • 1,827
  • 1
  • 17
  • 21
3

This was pretty useful System Wide Install With rbenv Specifically changing the permissions of rbenv directory to a group the users are in:

chgrp -R staff /usr/local/rbenv chmod -R g+rwxXs /usr/local/rbenv

techbrownbags
  • 618
  • 5
  • 10