Recently I’ve re-installed Nodejs, python, and Ruby on my work machine. When installing Ruby via Homebrew I was having trouble using it after installation, then my collegue figured out that brew info ruby
outputs this message:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
By default, binaries installed by gem will be placed into :
/usr/local /lib/ruby/gems/2.6 .0 /bin
You may want to add this to your PATH.
ruby is keg-only, which means it was not symlinked into /usr/local ,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.
If you need to have ruby first in your PATH run :
echo 'export PATH="/usr/local/opt/ruby/bin:$PATH" ' >> ~/.zshrc
For compilers to find ruby you may need to set :
export LDFLAGS="-L/usr/local/opt/ruby/lib"
export CPPFLAGS="-I/usr/local/opt/ruby/include"
At this point I think it’s probably just better avoid installing Ruby via homebrew. I searched a bit and decided to go with version managers like nvm.
This article is a quick note on what I ended up using for each language and how did I installed them.
Ruby rbenv https://github.com/rbenv/rbenv.git
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$ git clone https://github.com/rbenv/rbenv.git ~/.rbenv
$ cd ~/.rbenv
$ git checkout {version_tag}
$ mkdir -p "$(rbenv root) " /plugins
$ git clone https://github.com/rbenv/ruby-build.git "$(rbenv root) " /plugins/ruby-build
$ cd "$(rbenv root) " /plugins/ruby-build
$ git checkout {version_tag}
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
rbenv install 2.6.3
rbenv global 2.6.3
gem install sass
gem install compass
I’d like to make my .bashrc
more portable so I added some checks to see if rbenv is installed before executing rbenv init
:
1
2
3
4
5
6
7
8
9
10
11
command_exists () {
type "$1 " &> /dev/null ;
}
if [ -d "$HOME /.rbenv/" ]; then
export PATH="$HOME /.rbenv/bin:$PATH "
if command_exists rbenv; then
eval "$(rbenv init -) "
fi
fi
python pyenv https://github.com/pyenv/pyenv
The step is pretty much similar to rbenv in general1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$ git clone https://github.com/pyenv/pyenv.git ~/.pyenv
$ cd ~/.pyenv
$ git checkout {version_tag}
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
pyenv install 3.7.3
pyenv global 3.7.3
pip install pipenv
Similarly, I also added some checks before doing pyenv init
, so that it won’t break if I’m in an environment without pyenv:1
2
3
4
5
6
7
if [ -d "$HOME /.pyenv/" ]; then
export PYENV_ROOT="$HOME /.pyenv"
export PATH="$PYENV_ROOT /bin:$PATH "
if command_exists pyenv; then
eval "$(pyenv init -) "
fi
fi
Node.js nvm https://github.com/nvm-sh/nvm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$ git clone https://github.com/nvm-sh/nvm.git ~/.nvm
$ cd ~/.nvm
$ git checkout {version_tag}
export NVM_DIR="$HOME /.nvm"
[ -s "$NVM_DIR /nvm.sh" ] && \. "$NVM_DIR /nvm.sh"
[ -s "$NVM_DIR /bash_completion" ] && \. "$NVM_DIR /bash_completion"
$ nvm install 10
$ nvm use 10
$ nvm alias default 10
$ npm install
Again, making .bashrc
more general by checking file existence beforehand:1
2
3
export NVM_DIR="$HOME /.nvm"
[ -s "$NVM_DIR /nvm.sh" ] && \. "$NVM_DIR /nvm.sh"
[ -s "$NVM_DIR /bash_completion" ] && \. "$NVM_DIR /bash_completion"
Note: to use nvm in fish shell, install fisher and do fisher add FabioAntunes/fish-nvm