Installing ruby on ubuntu on my first VPS - ruby

I'm new to ruby and ubuntu and just created my first VPS droplet for deployment of my rails app. For setting it up I followed Railscast #335, which recommended using rbenv-installer for installing Ruby.
After running:
curl https://raw.githubusercontent.com/fesplugas/rbenv-installer/master/bin/rbenv-installer | bash
I get the message:
Seems you still have not added 'rbenv' to the load path:
# ~/.bash_profile:
export RBENV_ROOT="${HOME}/.rbenv"
if [ -d "${RBENV_ROOT}" ]; then
export PATH="${RBENV_ROOT}/bin:${PATH}"
eval "$(rbenv init -)"
fi
The railscast suggests adding it to ~/.bashrc using vim (who ever created this user interface??) and then excuting this file using . ~/.bashrc which I followed.
However, when running rbenv bootsrap-ubuntu-14-4 I get the message:
The program 'rbenv' is currently not installed. You can install it by typing:
apt-get install rbenv
Which I think is not the point.
Am I doing something wrong here?

The following worked for me, thanks to the tip from #kristianp:
https://www.brightbox.com/blog/2016/01/06/ruby-2-3-ubuntu-packages/
$ sudo apt-add-repository ppa:brightbox/ruby-ng
$ sudo apt-get update
Install the package:
$ sudo apt-get install ruby2.3 ruby2.3-dev
And you’re up and running:
$ ruby2.3 -v
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux-gnu]
Cheerio!

Related

Updating fastlane fails: signet requires Ruby version >= 2.4.0

I'm unable to update fastlane.
When I execute fastlane update_fastlane I get the following error.
ERROR: Error installing fastlane:
signet requires Ruby version >= 2.4.0.
When I execute ruby -v I get ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin18]
I'm stuck at fastlane version 2.28.3. I have tried reinstalling fastlane but I still get the same error.
What can be the cause of this issue? How can I resolve this?
Use this approach.
Remove fastlane from homebrew. Open terminal and run:
brew cask uninstall fastlane
Install ruby environments. Run in terminal:
brew install rbenv ruby-build
echo "" >> ~/.bash_profile
echo 'export PATH=${HOME}/homebrew/bin:${PATH}' >> ~/.bash_profile
echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile
rbenv install 2.6.5
rbenv global 2.6.5
exit
Open terminal again and run:
gem install fastlane
fastlane -v
Inspiration form:
https://hackernoon.com/the-only-sane-way-to-setup-fastlane-on-a-mac-4a14cb8549c8
I was able to install following the steps provided by gdingenen: https://github.com/fastlane/fastlane/issues/15467#issuecomment-540964272
Delete the .fastlane folder from the user's home folder
rm -r -df ~/.fastlane
Install using gem
sudo gem install fastlane -NV
You just need to replace the old ruby with the lastest one.
Find the lastest one. Execute which ruby, my result is /usr/local/opt/ruby/bin/ruby.
Find the old one. It's /Users/username/.fastlane/bin/bundle/bin/ruby
Replace it. Done.

ruby, gem, rbenv command not found

I've been setting up some ruby dependencies throughout a day on my Lubuntu (18.04) in VM. I installed ruby 2.4.0 and then installed rbenv and set 2.4.0 as global version to be used (probably reverse order). Then I installed bundler and started installing dependencies for my Sinatra app. Since I needed some native extension I also installed libpq-dev via sudo apt-get install, installed pg gem and ran bundler again. And then I have
Command 'ruby' not found, but can be installed with:
sudo apt install ruby
Same with bundle or gem commands.
I can see that I have rbenv in /home/michalvantuch/.rbenv/bin/rbenv and also /home/michalvantuch/.rbenv/versions/2.4.0/.
My path:
/home/michalvantuch/.rbenv/plugins/ruby-build/bin:/home/michalvantuch/.rbenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
My bash history:
bundle install
gem install pg -v '0.21.0' --source 'https://rubygems.org/'
vi /home/michalvantuch/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/extensions/x86_64-linux/2.4.0-static/pg-0.21.0/mkmf.log
sudo apt-get install libpq-dev
gem install pg -v '0.21.0' --source 'https://rubygems.org/'
bundle install
gem list --local
cd /home/michalvantuch/.rbenv/bin/
ls -lah
C rbenv -> ../libexec/rbenv
cd rbenv -> ../libexec/rbenv
cd rbenv
cd ../libexec/
ls -lah
pwd
cd ..
I'm weary and not sure how to fix this. Did I mess up with the system privileges ?
Complete setup commands for rbenv in linux machines
Initial setup
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
cd ~/.rbenv && src/configure && make -C src
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
~/.rbenv/bin/rbenv init
check whether eval "$(rbenv init -)" is present in ~/.bashrc. If not present run the following command
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
Then,
source ~/.bashrc
mkdir -p "$(rbenv root)"/plugins
git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
source ~/.bashrc
rbenv rehash
Now, rbenv installed. Now install your ruby version ( change the version below to your version). And set that to global version. (Use latest stable version as global as it is a good practice. You can set local versions differently depending on your working project)
rbenv install 2.5.1
rbenv global 2.5.1
Finished.
So, it turns out I figured it out myself.
What I was missing (rbenv doctor helped me) was to have shims in my PATH. Adding
eval "$(rbenv init -)"
did the trick.

How do I install ruby gems on Mac

How do I install RubyGems on my Mac?
I tried to run $ gem install rubygems-update with no luck . It returns
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
Any help would be great. Thanks
I would highly suggest using a package manager and a Ruby Environment Manager.
On Mac:
brew update
brew install ruby
# If you use bash
echo 'export PATH=/usr/local/Cellar/ruby/2.4.1_1/bin:$PATH' >> ~/.bash_profile
# If you use ZSH:
echo 'export PATH=/usr/local/Cellar/ruby/2.4.1_1/bin:$PATH' >> ~/.zprofile
You can do that but I suggest using an Environment Manager for Ruby.
You have rbenv and RVM.
IMO go for rbenv:
brew install rbenv ruby-build
# bash
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
# zsh
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zprofile
echo 'eval "$(rbenv init -)"' >> ~/.zprofile
# list all available versions:
rbenv install -l
# install a Ruby version:
rbenv install 2.4.1
# set ruby version for a specific dir
rbenv local 2.4.1
# set ruby version globally
rbenv global 2.4.1
rbenv rehash
gem update --system
One more variant is to use brew-gem.
https://formulae.brew.sh/formula/brew-gem
https://github.com/sportngin/brew-gem
Just copy/paste from the documentation:
brew install brew-gem
Usage
brew gem install heroku
To install a specific version: brew gem install heroku 3.8.3
To install using a brew installed ruby(/usr/local/bin/ruby): brew gem install heroku --homebrew-ruby
And with a specific version: brew gem install heroku 3.8.3 --homebrew-ruby
To upgrade: brew gem upgrade heroku
To uninstall: brew gem uninstall heroku
To check information: brew gem info heroku
Note: Installed gems are listed in brew list with prefix of gem-, like gem-heroku.
After installing cocoapods as Tulon suggested the thing which worked for me was passing the --user-install flag to the gem install command e.g
gem install rubygems-update --user-install
from https://guides.cocoapods.org/using/getting-started.html#sudo-less-installation
You may have to install manually in which case (as per the official website):
Go to the official website and download the zip file
Unzip the file in a directory.
Then go to the directory in your terminal and run: ruby setup.rb
It is showing that you don't have the permission to write something in that directory. Instead use this directory :
sudo gem install -n /usr/local/bin cocoapods
It perfectly work for me.
(I am using macOS Sierra, version 10.12.6)

Installing Ruby 2.3 on WSL (Windows Subsystem for Linux)

First off, sorry for my bad English.
I'm trying to install Ruby 2.3.0 on my system with rbenv via Windows Subsystem for Linux aka Ubuntu on Windows 10. I followed this instruction (but not 100% exactly). but every time I try, It fails to build Ruby with this log.
check struct members..
check libraries....
Use ActiveTcl libraries (if available).
Search tclConfig.sh and tkConfig.sh..............................
Fail to find [tclConfig.sh, tkConfig.sh]
Use X11 libraries (or use TK_XINCLUDES/TK_XLIBSW information on tkConfig.sh).
Warning:: cannot find X11 library. tcltklib will not be compiled (tcltklib is disabled on your Ruby. That is, Ruby/Tk will not work). Please check configure options. If your Tcl/Tk don't require X11, please try --without-X11.
Can't find X11 libraries.
So, can't make tcltklib.so which is required by Ruby/Tk.
Failed to configure tk. It will not be installed.
Failed to configure tk/tkutil. It will not be installed.
configuring zlib
make[1]: Entering directory `/tmp/ruby-build.20160522033606.7696/ruby-2.3.1'
make -C ext/digest/sha2 -w --jobserver-fds=6,7 -j V= realclean
make[2]: Entering directory `/tmp/ruby-build.20160522033606.7696/ruby-2.3.1/ext/digest/sha2'
Makefile:39: *** missing separator. Stop.
make[2]: Leaving directory `/tmp/ruby-build.20160522033606.7696/ruby-2.3.1/ext/digest/sha2'
make[1]: *** [ext/digest/sha2/realclean] Error 2
make[1]: Leaving directory `/tmp/ruby-build.20160522033606.7696/ruby-2.3.1'
make: *** [build-ext] Error 2
and this is my installed package list
libx11-data/trusty,now 2:1.6.2-1ubuntu2 all [installed]
libx11-dev/trusty,now 2:1.6.2-1ubuntu2 amd64 [installed]
libx11-doc/trusty,now 2:1.6.2-1ubuntu2 all [installed,automatic]
libx11-xcb1/trusty,now 2:1.6.2-1ubuntu2 amd64 [installed,automatic]
libtk8.4/trusty,now 8.4.20-7 amd64 [installed,automatic]
libtcl8.4/trusty,now 8.4.20-7 amd64 [installed,automatic]
As you see, I installed X11, tcl, tk but my system can't detect them.
Have I done wrong? or it is just a bug?
Any help would be appreciated. Thank you for reading.
My installation follow this tutorial, go there for most recent update: link here.
1. Install Ruby
First some dependencies for Ruby:
sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common libffi-dev
Now for Ruby: there are 3 ways to install, each way conflict with each other, so choose one you think fit yours most or my suggestion: rbenv
Using rbenv (recommend)
cd
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL
rbenv install 2.3.1
rbenv global 2.3.1
ruby -v
Using rvm
sudo apt-get install libgdbm-dev libncurses5-dev automake libtool bison libffi-dev
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
curl -sSL https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
rvm install 2.3.1
rvm use 2.3.1 --default
ruby -v
From the source
cd
wget http://ftp.ruby-lang.org/pub/ruby/2.3/ruby-2.3.1.tar.gz
tar -xzvf ruby-2.3.1.tar.gz
cd ruby-2.3.1/
./configure
make
sudo make install
ruby -v
After install Ruby, install Bundler
gem install bundler
2. Install Rails
First you need NodeJS:
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs
Then install rails:
gem install rails -v 4.2.6
If you're using rbenv, you'll need to run the following command to make the rails executable available:
rbenv rehash
Now that you've installed Rails, you can run the rails -v command to make sure you have everything installed correctly:
rails -v
# Rails 4.2.6
3. Install DB
MySQL:
You can install MySQL server and client from the packages in the Ubuntu repository. As part of the installation process, you'll set the password for the root user. This information will go into your Rails app's database.yml file in the future.
sudo apt-get install mysql-server mysql-client libmysqlclient-dev
PostgreSQL:
Currently, some bug prevents you from installing Postgres correctly, so I recommend you MySQL for now.
sudo sh -c "echo 'deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main' > /etc/apt/sources.list.d/pgdg.list"
wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-common
sudo apt-get install postgresql-9.5 libpq-dev
The Postgres installation doesn't setup a user for you, so you'll need to follow these steps to create a user with permission to create databases. Feel free to replace chris with your username.
sudo -u postgres createuser chris -s
# If you would like to set a password for the user, you can do the following
sudo -u postgres psql
postgres=# \password chris
Final Steps
Now make sure things go right not left
#### If you want to use SQLite (not recommended)
rails new myapp
#### If you want to use MySQL
rails new myapp -d mysql
#### If you want to use Postgres
# Note that this will expect a postgres user with the same username
# as your app, you may need to edit config/database.yml to match the
# user you created earlier
rails new myapp -d postgresql
# Move into the application directory
cd myapp
# If you setup MySQL or Postgres with a username/password, modify the
# config/database.yml file to contain the username/password that you specified
# Create the database
rake db:create
rails server
Make sure you have updated your Windows installation - run 'Windows 10 Upgrade Assistant' and install the Windows 10 Creators Update. Anything before this is riddled with bugs and my rbenv Rails install wouldn't work. If it still won't work after updating Windows to CU then you can always just use rvm instead. You may need to reinstall everything anyway, as its recommended to reinstall/upgrade Ubuntu if you are using WSL.

The command rbenv install is missing

In Ubuntu 10.04 I just installed rbenv.
The install command is not present.
rbenv 0.4.0-49-g8b04303
Usage: rbenv <command> [<args>]
Some useful rbenv commands are:
commands List all available rbenv commands
local Set or show the local application-specific Ruby version
global Set or show the global Ruby version
shell Set or show the shell-specific Ruby version
rehash Rehash rbenv shims (run this after installing executables)
version Show the current Ruby version and its origin
versions List all Ruby versions available to rbenv
which Display the full path to an executable
whence List all Ruby versions that contain the given executable
See `rbenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/sstephenson/rbenv#readme
What am I missing?
The install command is not embedded into rbenv, it comes from the ruby-build plugin. You can install it using the command:
git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
On Mac OS X you can install it through homebrew:
brew install ruby-build
On Debian (version >= 7) and Ubuntu (version >= 12.10) both rbenv and ruby-build can be installed using apt-get (or aptitude):
sudo apt-get update
sudo apt-get install rbenv ruby-build
On FreeBSD ruby-build is available in the Ports Collection, it can be install both as a binary package or build from the port:
# Using pkgng rbenv will be installed
pkg install ruby-build
# Building ruby-build form Ports will install rbenv only if the RBENV option is set
cd /usr/ports/devel/ruby-build
make install
I found that when using rbenv from a global directory, it's necessary to export the RBENV_ROOT variable, otherwise it won't load the plugins.
export RBENV_ROOT="/usr/local/rbenv"
if [ -d "${RBENV_ROOT}" ]; then
export PATH="${RBENV_ROOT}/bin:${PATH}"
fi
As everyone mentioned problem is missing ruby-build. For older versions of OS ruby-build may not be available as an apt package. In that case install using original instructions, which should've omitted the word Optional in this:
(Optional) Install ruby-build, which provides the rbenv install
command that simplifies the process of installing new Ruby versions.
git clone git#github.com:rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
# OR use http
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
Simply install ruby-build in ubuntu:
sudo apt-get install ruby-build
And add
eval "$(rbenv init -)"
To your ~/.bashrc
I had installed the ruby-build plugin before and installed ruby 1.9.3-p327 using
$ rbenv install 1.9.3-p327
A few days later I tried to install ruby 2.0.0-p247 using
$ rbenv install 2.0.0-p247
but I received the error message
rbenv: no such command 'install'
All I had to do was to run
$ exec $SHELL -l
and that fixed the problem.
Answered on 2021
If you're getting that error, it's very likely you have accidentally skipped one of the installation instructions:
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL
Replace .bashrc with whatever shell you're using, for example .zshrc, or just manually access your shell config file and paste this line:
export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"
I strong advise against re-installing/installing Ruby via brew or apt-get just to get around this issue. The whole point of using rbenv is to make your life easier in future when there is ruby version upgrade, or when you're working on different rails projects that require different version of ruby.
It looks like ruby-build is not present. Run this command :
git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
Anyone finding their way here with this issue on OSX and already having installed ruby-build via homebrew (like me), you may solve this by just upgrading ruby-build:
brew update
brew upgrade ruby-build
This fixed the problem for me.
This issue also happens in Linux when doing a stand-alone installation of ruby-build, if the ruby-build executable is not found in the path. If installing under /usr/local, try for example:
PATH=/usr/local/bin:$PATH /usr/local/bin/rbenv install ...
I came to this solution, but looking for a macOS solution that uses MacPorts.
So, here the same command using MacPorts:
➜ ~ sudo port install ruby-build
Password:
---> Computing dependencies for ruby-build
---> Fetching archive for ruby-build
---> Attempting to fetch ruby-build-20210804_0.darwin_19.noarch.tbz2 from https://packages.macports.org/ruby-build
---> Attempting to fetch ruby-build-20210804_0.darwin_19.noarch.tbz2.rmd160 from https://packages.macports.org/ruby-build
---> Installing ruby-build #20210804_0
---> Activating ruby-build #20210804_0
---> Cleaning ruby-build
---> Scanning binaries for linking errors
---> No broken files found.
---> No broken ports found.
➜ ~ curl -fsSL https://github.com/rbenv/rbenv-installer/raw/main/bin/rbenv-doctor | bash
Checking for `rbenv' in PATH: /opt/local/bin/rbenv
Checking for rbenv shims in PATH: OK
Checking `rbenv install' support: /opt/local/bin/rbenv-install (ruby-build 20210804)
Counting installed Ruby versions: none
There aren't any Ruby versions installed under `/Users/user/.rbenv/versions'.
You can install Ruby versions like so: rbenv install 3.0.2
Checking RubyGems settings: OK
Auditing installed plugins: OK
➜ ~ rbenv install 3.0.2
Downloading openssl-1.1.1k.tar.gz...
-> https://dqw8nmjcqpjn7.cloudfront.net/892a0875b9872acd04a9fde79b1f943075d5ea162415de3047c327df33fbaee5
Installing openssl-1.1.1k...

Resources