You need to prefix the gem
command with sudo
because /var/lib/gems
is owned by root
. You could also take a look at RVM which allows really easy installation and management of gems and Ruby versions. Best part, it’s all in your home dir!
EDIT: per @AndrewMarshall’s comment bellow, rbenv is an alternative to RVM.