<\/span><\/h2>\n\n\n\nBefore proceeding with the actual installation, we need to run a full system update. So, to do that, run the following on your SSH as root:<\/p>\n\n\n\n
$ dnf update -y<\/code><\/pre>\n\n\n\n<\/span>Step 2. Install Ruby on Rails<\/span><\/h2>\n\n\n\nAs the ruby package is already present on Almalinux, to install it, we’ll run:<\/p>\n\n\n\n
$ sudo dnf install ruby ruby-devel<\/code><\/pre>\n\n\n\nAs Rails depends on the Development tools package to be installed, be sure to run:<\/p>\n\n\n\n
$ sudo dnf group install \"Development Tools\" -y<\/code><\/pre>\n\n\n\nThis will ensure that our Rails installation will work fine.<\/p>\n\n\n\n
<\/span>Step 3. Installing PostgreSQL<\/span><\/h2>\n\n\n\nFor our PostgreSQL installation, we’ll use the APPStream repository. To add the repository to your system, you need to run:<\/p>\n\n\n\n
$ sudo dnf install -y https:\/\/download.postgresql.org\/pub\/repos\/yum\/reporpms\/EL-9-x86_64\/pgdg-redhat-repo-latest.noarch.rpm<\/code><\/pre>\n\n\n\nThen, to install the service, you run:<\/p>\n\n\n\n
$ sudo dnf install -y postgresql15-server postgresql15-contrib libpq5-devel<\/code><\/pre>\n\n\n\nAs soon as your installation is completed, you can initiate the PostgreSQL configuration with:<\/p>\n\n\n\n
$ sudo postgresql-15-setup initdb<\/code><\/pre>\n\n\n\nBe sure also to start the service and enable it to boot with your system:<\/p>\n\n\n\n
$ sudo systemctl start postgresql-15 $ sudo systemctl enable postgresql-15<\/code><\/pre>\n\n\n\n<\/span>Step 4. Installing NodeJS and Yarn<\/span><\/h2>\n\n\n\nSince Ruby on Rails is more focused on back-end services, we need software that will compile our front-end assets. This will be handled by NodeJS\/Yarn. To install NodeJS, we need to run:<\/p>\n\n\n\n
$ sudo dnf install nodejs npm -y<\/code><\/pre>\n\n\n\nAnd yarn is installed using this command:<\/p>\n\n\n\n
$ sudo npm install -g yarn<\/code><\/pre>\n\n\n\nYarn package by default uses \/usr\/local\/bin<\/code> path. If your system $PATH variable does not include this path, be sure to run:<\/p>\n\n\n\n$ echo \"export PATH=$PATH:\/usr\/local\/bin\" >> ~\/.bashrc $ source ~\/.bashrc<\/code><\/pre>\n\n\n\n<\/span>Step 5. Installing Ruby on Rails via Gem Manager<\/span><\/h2>\n\n\n\nWe need to install Ruby on Rails using Gem as any other modules\/dependencies, etc. from Ruby on Rails are installed with the gem command as well. So, to install it after installing all dependencies, you need to run:<\/p>\n\n\n\n
$ sudo gem install rails<\/code><\/pre>\n\n\n\n<\/span>Step 6. Creating a PostgreSQL role<\/span><\/h2>\n\n\n\nWe need to create a PostgreSQL role (user) to manage the database. This user will need to have the “management” role, so the user can create\/delete databases, etc.<\/p>\n\n\n\n
So, first of all, to manage the PostgreSQL service, you need to login to the postgres<\/code> user.<\/p>\n\n\n\n$ su - postgres psql<\/code><\/pre>\n\n\n\nWhen you’re logged in as the postgres<\/code> user, you can create our role with:<\/p>\n\n\n\nCREATE ROLE rails WITH CREATEDB LOGIN PASSWORD 'Y0ur_S3cur3_P4ssw0rd';<\/code><\/pre>\n\n\n\nMake sure to change Y0ur_S3cur3_P4ssw0rd to a unique password. To confirm your user is created properly, you can list all users with:<\/p>\n\n\n\n
\\du<\/code><\/pre>\n\n\n\n<\/span>Step 7. Creating a Rails Project<\/span><\/h2>\n\n\n\nIn this last section, we’ll deploy our Rails project. To do that, we’ll start by creating the folder \/var\/www\/<\/code> and entering it:<\/p>\n\n\n\n$ mkdir -p \/var\/www; cd \/var\/www<\/code><\/pre>\n\n\n\nNow that we are inside our folder, we can create the project:<\/p>\n\n\n\n
$ rails new rails_project --database=postgresql<\/code><\/pre>\n\n\n\nAfter your project is created, you need to change your directory to it:<\/p>\n\n\n\n
$ cd rails_project\/<\/code><\/pre>\n\n\n\nThen, edit the database file so we can setup our password we set before:<\/p>\n\n\n\n
$ nano config\/database.yml<\/code><\/pre>\n\n\n\ndevelopment:\n<<: *default\ndatabase: rails_development\nusername: rails\npassword: Y0ur_S3cur3_P4ssw0rd\nhost: localhost\nport: 5432\n\ntest:\n<<: *default\ndatabase: rails_test\nuser: rails\npassword: Y0ur_S3cur3_P4ssw0rd\nhost: localhost\nport: 5432\n\nproduction:\n<<: *default\ndatabase: rails_production\nusername: rails\npassword: Y0ur_S3cur3_P4ssw0rd\nhost: localhost\nport: 5432<\/code><\/pre>\n\n\n\nAfter changing\/adding the values, you can save the file and exit the editor.<\/p>\n\n\n\n
Next, to migrate the database we need to run:<\/p>\n\n\n\n
$ rails db:setup $ rails db:migrate<\/code><\/pre>\n\n\n\nAfter the migrate command is finished, you can finally start your rails server with the command:<\/p>\n\n\n\n
$ rails server --binding=0.0.0.0<\/code><\/pre>\n\n\n\nAnd, if you receive a positive output, you are good to go, and you can access your website at http:\/\/your_ip:3000.<\/p>\n\n\n\n
That’s it, we have successfully installed Ruby on Rails on a VPS server with AlmaLinux 9. <\/p>\n\n\n\n
If you find all of this a little too overwhelming or if you’re getting errors, why not sign up for one of our Ruby on Rails hosting plans? Our VPSes are one of the fastest you can find anywhere, and our managed support covers all aspects of your server and software, not just Ruby on Rails or your OS. Try us – you won’t regret it.<\/p>\n\n\n\n
If you liked this post on how to install Ruby on Rails together with PostgreSQL on AlmaLinux 9, please share it with your friends & followers on social media, or leave a comment below if you have anything to add or any questions. Thanks.<\/p>\n","protected":false},"excerpt":{"rendered":"
Ruby on Rails, often referred to as Rails, is a popular open-source web application framework written in Ruby. It\u2019s known … <\/p>\n
Read More<\/a><\/p>\n","protected":false},"author":4,"featured_media":47370,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1699,2072,13,1712],"tags":[1910,141],"yoast_head":"\nHow to Install Ruby on Rails with PostgreSQL on AlmaLinux 9 - RoseHosting<\/title>\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\t \n\t \n\t \n \n \n \n \n \n\t \n\t \n\t \n