Setting up Ruby on Rails like an idiot
This is a pretty fair one; I am a SysAdmin with multiple different systems to show painstaiking love and attention to but then someone makes a request, from one of the 'higher' levels, requesting a certain system.
That system, for me, is "Ruby on Rails". I need to "give them Ruby on Rails", so that they can "learn Ruby".
Great. Time to learn a thing. Also; I'm too drunk to really "format" this shit properly so I'm sorry if I call you out or some shit.
You have been so absolutely warned; I am absolutely against Ruby on principle; from their arrogant documentation to their horrific implementation in production (from what I have read), I absolutely despise Ruby. I do not program in Ruby nor do I understand anything about what I'm doing from this point on.
We can and do argue Ruby a lot in our channels but it's not going away so us sysadmins have to put up and shut up; here's how I setup a dev-level system for our developers to learn Ruby.
Configuring the System
Ruby runs in the user environment as far as I can tell and the way we're going to set it up is user-specific. Lovely.
CentOS 7 Minimal was installed to a VM. System specs dont really matter here. I created myself a user and our dev team a user. It's also worth noting that if you want to run Ruby on Rails then you need Ruby 2.2.2 or later as of writing, and you will need SQLite3 because according to Ruby's maintainers; almost projects will need a database.
I did a bit of research and landed on rvm for managing my Ruby versions. They have a multi-user install which we'll be using because we will have two or three users on this system - I have plucked the following command from their documentation. According to the documentation, this must be done as a non-root user to avoid sudo and rvmsudo issues later on. I repeat; this must NOT BE DONE AS ROOT. How stupid is that?
curl -sSL https://rvm.io/mpapis.asc | sudo gpg --import - curl -sSL https://rvm.io/pkuczynski.asc | sudo gpg --import - \curl -sSL https://get.rvm.io | sudo bash -s stable
I put these into a file and ran it with bash.
[jmb@ror ~]$ bash 1 gpg: keyring `/root/.gnupg/secring.gpg' created gpg: /root/.gnupg/trustdb.gpg: trustdb created gpg: key D39DC0E3: public key "Michal Papis (RVM signing) <firstname.lastname@example.org>" imported gpg: Total number processed: 1 gpg: imported: 1 (RSA: 1) gpg: no ultimately trusted keys found gpg: key 39499BDB: public key "Piotr Kuczynski <email@example.com>" imported gpg: Total number processed: 1 gpg: imported: 1 (RSA: 1) Downloading https://github.com/rvm/rvm/archive/1.29.7.tar.gz Downloading https://github.com/rvm/rvm/releases/download/1.29.7/1.29.7.tar.gz.asc gpg: Signature made Fri 04 Jan 2019 09:01:48 AEDT using RSA key ID 39499BDB gpg: Good signature from "Piotr Kuczynski <firstname.lastname@example.org>" gpg: WARNING: This key is not certified with a trusted signature! gpg: There is no indication that the signature belongs to the owner. Primary key fingerprint: 7D2B AF1C F37B 13E2 069D 6956 105B D0E7 3949 9BDB GPG verified '/usr/local/rvm/archives/rvm-1.29.7.tgz' Creating group 'rvm' Installing RVM to /usr/local/rvm/ Installation of RVM in /usr/local/rvm/ is almost complete: * First you need to add all users that will be using rvm to 'rvm' group, and logout - login again, anyone using rvm will be operating with `umask u=rwx,g=rwx,o=rx`. * To start using RVM you need to run `source /etc/profile.d/rvm.sh` in all your open shell windows, in rare cases you need to reopen all shell windows. * Please do NOT forget to add your users to the rvm group. The installer no longer auto-adds root or users to the rvm group. Admins must do this. Also, please note that group memberships are ONLY evaluated at login time. This means that users must log out then back in before group membership takes effect!
Now you need to add your users to the rvm group. At the moment, I only have a single user so it's pretty simple however we will need to remember to add users to the rvm group when we create them:
[jmb@ror ~]$ sudo usermod -a -G rvm jmb [jmb@ror ~]$ source /etc/profile [jmb@ror ~]$ echo $PATH /usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/itadmin/.local/bin:/home/itadmin/bin:/usr/local/rvm/bin
You can now use the rvm command. You might have been able to before... who knows?
I had to take a huge break because of work related reasons, but I'm back. Unfortunately, I've blown off our web developers (ew not like that) for about two or three months on this because I have much better shit to do than something that doesn't contribute to the operation of our business but now it's become a priority (somehow) and I have to do it basically today.
I've switched from my jmb user to my web user. That's all.
You can now install a version of Ruby that tickles your fancy. For this, we'll be using the minimum of Ruby that Rails supports.
$ rvm install 2.1 Searching for binary rubies, this might take some time. Found remote file https://rvm_io.global.ssl.fastly.net/binaries/centos/7/x86_64/ruby-2.1.10.tar.bz2 Checking requirements for centos. Installing requirements for centos. Installing required packages: patch, autoconf, automake, bison, bzip2, gcc-c++, libffi-devel, libtool, patch, readline-devel, sqlite-devel, zlib-devel, glibc-headers, glibc-devel, openssl-devel...web password required for 'yum install -y patch autoconf automake bison bzip2 gcc-c++ libffi-devel libtool patch readline-devel sqlite-devel zlib-devel glibc-headers glibc-devel openssl-devel': Error running 'requirements_centos_libs_install patch autoconf automake bison bzip2 gcc-c++ libffi-devel libtool patch readline-devel sqlite-devel zlib-devel glibc-headers glibc-devel openssl-devel', please read /usr/local/rvm/log/1553738297_ruby-2.1.10/package_install_patch_autoconf_automake_bison_bzip2_gcc-c++_libffi-devel_libtool_patch_readline-devel_sqlite-devel_zlib-devel_glibc-headers_glibc-devel_openssl-devel.log Requirements installation failed with status: 141.
Finally; I prove a point. Rvm is rqeuiring me to install a bunch of stuff which requires sudo access on this account. I'm interested to see if this is a one-off thing, so drop back into your root account and install these packages.
[root@ror ~]# yum install -y patch autoconf automake bison bzip2 gcc-c++ libffi-devel libtool patch readline-devel sqlite-devel zlib-devel glibc-headers glibc-devel openssl-devel ... Installed: autoconf.noarch 0:2.69-11.el7 automake.noarch 0:1.13.4-3.el7 bison.x86_64 0:3.0.4-2.el7 bzip2.x86_64 0:1.0.6-13.el7 gcc-c++.x86_64 0:4.8.5-36.el7_6.1 glibc-devel.x86_64 0:2.17-260.el7_6.3 glibc-headers.x86_64 0:2.17-260.el7_6.3 libffi-devel.x86_64 0:3.0.13-18.el7 libtool.x86_64 0:2.4.2-22.el7_3 openssl-devel.x86_64 1:1.0.2k-16.el7_6.1 patch.x86_64 0:2.7.1-10.el7_5 readline-devel.x86_64 0:6.2-10.el7 sqlite-devel.x86_64 0:3.7.17-8.el7 zlib-devel.x86_64 0:1.2.7-18.el7 Dependency Installed: cpp.x86_64 0:4.8.5-36.el7_6.1 gcc.x86_64 0:4.8.5-36.el7_6.1 kernel-headers.x86_64 0:3.10.0-957.10.1.el7 keyutils-libs-devel.x86_64 0:1.5.8-3.el7 krb5-devel.x86_64 0:1.15.1-37.el7_6 libcom_err-devel.x86_64 0:1.42.9-13.el7 libkadm5.x86_64 0:1.15.1-37.el7_6 libmpc.x86_64 0:1.0.1-3.el7 libselinux-devel.x86_64 0:2.5-14.1.el7 libsepol-devel.x86_64 0:2.5-10.el7 libstdc++-devel.x86_64 0:4.8.5-36.el7_6.1 libverto-devel.x86_64 0:0.2.5-4.el7 m4.x86_64 0:1.4.16-10.el7 mpfr.x86_64 0:3.1.1-4.el7 ncurses-devel.x86_64 0:5.9-14.20130511.el7_4 pcre-devel.x86_64 0:8.32-17.el7 perl-Data-Dumper.x86_64 0:2.145-3.el7 perl-Test-Harness.noarch 0:3.28-3.el7 perl-Thread-Queue.noarch 0:3.02-2.el7 Dependency Updated: e2fsprogs.x86_64 0:1.42.9-13.el7 e2fsprogs-libs.x86_64 0:1.42.9-13.el7 glibc.x86_64 0:2.17-260.el7_6.3 glibc-common.x86_64 0:2.17-260.el7_6.3 krb5-libs.x86_64 0:1.15.1-37.el7_6 libcom_err.x86_64 0:1.42.9-13.el7 libgcc.x86_64 0:4.8.5-36.el7_6.1 libgomp.x86_64 0:4.8.5-36.el7_6.1 libselinux.x86_64 0:2.5-14.1.el7 libselinux-python.x86_64 0:2.5-14.1.el7 libselinux-utils.x86_64 0:2.5-14.1.el7 libsepol.x86_64 0:2.5-10.el7 libss.x86_64 0:1.42.9-13.el7 libstdc++.x86_64 0:4.8.5-36.el7_6.1 ncurses.x86_64 0:5.9-14.20130511.el7_4 ncurses-base.noarch 0:5.9-14.20130511.el7_4 ncurses-libs.x86_64 0:5.9-14.20130511.el7_4 openssl.x86_64 1:1.0.2k-16.el7_6.1 openssl-libs.x86_64 1:1.0.2k-16.el7_6.1 zlib.x86_64 0:1.2.7-18.el7 Complete!
I know that's a lot of shit, but hopefully what's installed helps you in some way.
Back on the web account, we can continue the Ruby install to see if the above has solved our issues:
$ rvm install 2.1 find: failed to restore initial working directory: Permission denied Searching for binary rubies, this might take some time. Found remote file https://rvm_io.global.ssl.fastly.net/binaries/centos/7/x86_64/ruby-2.1.10.tar.bz2 Checking requirements for centos. Requirements installation successful. ruby-2.1.10 - #configure ruby-2.1.10 - #download % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 22.9M 100 22.9M 0 0 357k 0 0:01:05 0:01:05 --:--:-- 558k No checksum for downloaded archive, recording checksum in user configuration. ruby-2.1.10 - #validate archive ruby-2.1.10 - #extract ruby-2.1.10 - #validate binary Libraries missing for ruby-2.1.10: libyaml-0.so.2. Refer to your system manual for installing libraries Mounting remote ruby failed with status 10, trying to compile. Checking requirements for centos. Requirements installation successful. bash: /usr/local/rvm/scripts/functions/manage/install/centos: No such file or directory Installing Ruby from source to: /usr/local/rvm/rubies/ruby-2.1.10, this may take a while depending on your cpu(s)... ruby-2.1.10 - #downloading ruby-2.1.10, this may take a while depending on your connection... % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 11.4M 100 11.4M 0 0 494k 0 0:00:23 0:00:23 --:--:-- 1363k ruby-2.1.10 - #extracting ruby-2.1.10 to /usr/local/rvm/src/ruby-2.1.10..... ruby-2.1.10 - #configuring..................................................... ruby-2.1.10 - #post-configuration.. ruby-2.1.10 - #compiling........................................................................................................... ruby-2.1.10 - #installing................................. ruby-2.1.10 - #making binaries executable.. ruby-2.1.10 - #downloading rubygems-2.7.9 % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 842k 100 842k 0 0 1446k 0 --:--:-- --:--:-- --:--:-- 1450k No checksum for downloaded archive, recording checksum in user configuration. ruby-2.1.10 - #extracting rubygems-2.7.9..... ruby-2.1.10 - #removing old rubygems........ ruby-2.1.10 - #installing rubygems-2.7.9.................................... ruby-2.1.10 - #gemset created /usr/local/rvm/gems/ruby-2.1.10@global ruby-2.1.10 - #importing gemset /usr/local/rvm/gemsets/global.gems................................................................ ruby-2.1.10 - #generating global wrappers....... ruby-2.1.10 - #gemset created /usr/local/rvm/gems/ruby-2.1.10 ruby-2.1.10 - #importing gemsetfile /usr/local/rvm/gemsets/default.gems evaluated to empty gem list ruby-2.1.10 - #generating default wrappers....... ruby-2.1.10 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake). Install of ruby-2.1.10 - #complete Ruby was built without documentation, to build it run: rvm docs generate-ri
...Yeahp... let's move on. Because this is the only version installed it should be our default, and I don't really want to mess with that.
Let's get started with...
BOOM BOOM BOOOOOOOOOOOOM *partysirens.
First, triple check ruby and sqlite3 are installed;
[web@ror ~]$ ruby -v ; sqlite3 --version ruby 2.1.10p492 (2016-04-01 revision 54464) [x86_64-linux] 3.7.17 2013-05-20 00:56:22 118a3b35693b134d56ebd780123b7fd6f1497668
Now.. oh.. wait we fucked up.
gem install rails fails because it requiers a higher version of i18n, which requires at least Ruby 2.3. I could have sworn... oh.. no i was mistaken.
Well... no other way about it. Let's 'upgrade' our version of ruby installed!
[web@ror ~]$ rvm install 2.3 [web@ror ~]$ rvm remove 2.1 [web@ror ~]$ rvm use 2.3 [web@ror ~]$ ruby -v ruby 2.3.8p459 (2018-10-18 revision 65136) [x86_64-linux]
I want to know if i can trust 2.3 to actually be used so i logged out and logged in:
[web@ror root]$ ruby -v bash: ruby: command not found [web@ror root]$ gem install rails bash: gem: command not found
Figures. Totally unreliable. Anyway, onward.
[web@ror root]$ rvm use 2.3 Using /usr/local/rvm/gems/ruby-2.3.8 [web@ror root]$ gem install rails ... Done installing documentation for concurrent-ruby, thread_safe, tzinfo, i18n, activesupport, mini_portile2, nokogiri, rails-dom-testing, crass, loofah, rails-html-sanitizer, erubi, builder, actionview, rack, rack-test, actionpack, sprockets, sprockets-rails, method_source, thor, railties, mimemagic, marcel, arel, activemodel, activerecord, activestorage, websocket-extensions, websocket-driver, nio4r, actioncable, globalid, activejob, mini_mime, mail, actionmailer, rails after 88 seconds 38 gems installed [web@ror root]$ rails -v Rails 126.96.36.199
Okay so theoretically, we have Ruby 2.3 and Rails 'installed'.
So now I guess it's time to start "coding ruby on rails" or whatever the kids call it. To do this, Rails gives a pretty basic example of a blog which you can install from their .. rails .. thing.
[web@ror ~]$ rails new blog
While installing this it gave me a bunch of deprecation messages about chromedriver-helper and Ruby Sass. I have no idea what's up with either of these so like an idiot installing Rails, I'm ignoring them.
So apparently I have installed a blog. Let's look at our directory structure:
tree just for this. So we have a massive directory structure installed for a simple blog and now it's time to start coding.
But wait. Let's see what this beautiful blog looks like!
Oh, we can't. Because Ruby on Rails is trash. I have to fix this.
[root@ror ~]# yum -y install epel-release [root@ror ~]# yum -y install nodejs
now su back into web and go back into your blog/project directory
[web@ror web]# gem install execjs [web@ror web]# gem install therubyracer
I dont know if the above is required or if only nodejs is because I installed the above hoping to fix the issue.
Now the servers running for me.
[web@ror blog]$ bin/rails server => Booting Puma => Rails 188.8.131.52 application starting in development => Run `rails server -h` for more startup options Puma starting in single mode... * Version 3.12.1 (ruby 2.3.8-p459), codename: Llamas in Pajamas * Min threads: 5, max threads: 5 * Environment: development * Listening on tcp://localhost:3000 Use Ctrl-C to stop
What the FUCK is TCP and why the FUCK is it listening to localhost? Gah.
[web@ror blog]$ rails server -b 0.0.0.0 => Booting Puma => Rails 184.108.40.206 application starting in development => Run `rails server -h` for more startup options Puma starting in single mode... * Version 3.12.1 (ruby 2.3.8-p459), codename: Llamas in Pajamas * Min threads: 5, max threads: 5 * Environment: development * Listening on tcp://0.0.0.0:3000 Use Ctrl-C to stop
tcp just means... like.. http in ruby I guess because it works. It's broken.. but i'm not the coder who has to fix it up.
Packaging all of this up for web
So here's basically what I sent them;
Step 1. Learn to SSH Step 2. Learn to FTP Step 3. ??? Step 4. Profit.
I'm actually drunk sending this who cares. Enjoy. If you want to learn how to create real apps, go do something else.