Install Ruby with rbenv on macOS

This is a note on how to install rbenv on macOS and how to use it.

1. Install rbenv

Install rbenv.

Before install rbenv, you need to install xcode-select.

1
$ xcode-select --install

Install rbenv.

1
2
$ git clone https://github.com/rbenv/rbenv.git ~/.rbenv
$ cd ~/.rbenv && src/configure && make -C src

Add the following to .bash_profile

1
2
3
4
# rbenv
export RBENV_ROOT="$HOME/.rbenv"
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

Load .bash_profile in shell

1
$ source .bash_profile

Install ruby-build to build ruby.

1
2
$ mkdir -p "$(rbenv root)"/plugins
$ git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build

2. How to Use rbenv ( Install and manage Ruby )

How to check which version you can use.

1
$ rbenv install -l

How to check which version you insatlled.

1
$ rbenv versions

How to install the specified version of PHP.

1
$ rbenv install 2.4.3

Run this command after you install a new version of Ruby

1
$ rbenv rehash

How to use the specified version of Ruby at global.

1
$ rbenv global 2.4.3

How to use the specified version of Ruby at local ( directory ).

1
$ rbenv local 2.4.3

This command will create .ruby-version file at current directory.

3. How to use gem

You can use gem.
When you install gem packages global ( gem install *** ), the gem packages will installed at current version of ruby directory)( example: .rbenv/versions/2.4.3/lib/ruby/gems/ ).
So, you shuld use rbenv rehash command after install gem packages at global.
I think this is safe because the gem packages installed global is related Ruby version.

example.

1
2
$ gem install bundler
$ rbenv rehash

4. How to Update rbenv

1
2
$ cd $(rbenv root)
$ git pull

5. How to Update ruby-build

When a new version of Ruby is released, you need to update ruby-build. Otherwise you can not install the new version of Ruby.

1
2
$ cd $(rbenv root)/plugins/ruby-build
$ git pull

Install Node.js with nodenv on macOS

This is a note on how to install nodenv on macOS and how to use it.

1. Install nodenv

Install nodenv

1
2
$ git clone https://github.com/nodenv/nodenv.git ~/.nodenv
$ cd ~/.nodenv && src/configure && make -C src

Add the following to .bash_profile

1
2
3
# nodenv
export PATH="$HOME/.nodenv/bin:$PATH"
eval "$(nodenv init -)"

Load .bash_profile in shell

1
$ source .bash_profile

Install node-build to build Node.js.

1
$ git clone https://github.com/nodenv/node-build.git $(nodenv root)/plugins/node-build

2. How to Use nodenv ( Install and manage Node.js )

How to check which version you can use

1
$ nodenv install -l

How to check which version you insatlled

1
$ nodenv versions

How to install the specified version of Node.js

1
$ nodenv install 8.11.3

Run this command after you install a new version of Node.js.

1
$ nodenv rehash

How to use the specified version of Node.js at global

1
$ nodenv global 8.11.3

How to use the specified version of Node.js at local ( directory ).

1
$ nodenv local 8.11.3

This command will create .node-version file at current directory.

3. How to use npm

You can use npm.
When you install npm packages global ( npm install *** -g ), the npm packages will installed at current version of node.js directory)( example: .nodenv/versions/8.11.3/lib/node_modules/ ).
So, you shuld use nodenv rehash command after install npm packages at global.
I think this is safe because the npm packages installed global is related Node.js version.

example.

1
2
$ npm install grunt-cli
$ nodenv rehash

4. How to Update nodenv

1
2
$ cd $(nodenv root)
$ git pull

5. How to Update node-build

When a new version of Node.js is released, you need to update node-build. Otherwise you can not install the new version of Node.js.

1
2
$ cd $(nodenv root)/plugins/node-build
$ git pull

Creating SSH key on macOS and store passphrases in keychain

This is a memo of creating SSH key and store passphrases in keychain on macOS.
I referred Github SSH Setting Guite.

1. Generating a new SSH key

1
$ ssh-keygen -t rsa -b 4096 -C "xxx@example.com"

For security, it is important to create it with 4096 bits and set a passphrase for the private key

2. Setting SSH config

Setting SSH config for store passphrases in keychain.
Add the following setting to .ssh / config.

1
2
3
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa

3. Starting ssh-agent

Starting ssh-agent.

1
$ ssh-add -K ~/.ssh/id_rsa

When you want to start ssh-agent automatically when starting the shell. write the following in .bash_profile etc.

1
ssh-add -l || ssh-add -K ~/.ssh/id_rsa