Getting rbenv and ZSH to work on a Ubuntu Vagrant VM
When you get used to ZSH coupled by oh-my-zsh
the default bash/sh looks and feels as if they are tools used by stone-age men. That is exactly what I felt when ran vagrant ssh
in a Ruby on Rails project that was configured using a custom Chef cookbook using chef-solo
in a Vagrant/VirtualBox setup running Ubuntu 20.04. These are the steps I followed.
I installed zsh
and proceeded to install
$ sudo apt install zsh
$ sudo sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
Since it was installed with sudo
the owner/group of the files installed were root
. I changed it to `vagrant with:
$ sudo chown -R vagrant:vagrant ~/.oh-my-zsh
$ sudo chown vagrant:vagrant ~/.zshrc
Logging in and out proved that the chsh
step in the installation some how didn't work and that it was defaulting to bash. I fixed that using:
$ sudo chsh -s $(which zsh) vagrant
Then to maintain similar behaviour to bash, I sourced the files:
$ echo 'source ~/.bashrc' >> ~/.zshrc
$ echo 'source ~/.profile' >> ~/.zshrc
I logged out and logged in and Ruby was not working.
Upon checking the PATH, I noticed the rbenv
path was not set. After some investigation I came with this to get it work.
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc
$ echo 'eval "$(rbenv init -)"' >> ~/.zshrc
And all was good to go!
About the Author
Ziyan Junaideen -
Ziyan is an expert Ruby on Rails web developer with 8 years of experience specializing in SaaS applications. He spends his free time he writes blogs, drawing on his iPad, shoots photos.