Codeanywhere.com is a cloud based integrated development environment (IDE) that allows you to setup a development environment online, and true to its name, code from anywhere. One of my goals for 2022 is to get back into Rails development now that Rails 7 was released. The problem I was running into when getting back into the game appears to be caused by my new MacBook Pro computer with the M1 chip.
When getting a Ruby 3 and Rails 7 environment configured and ready to go, I found myself running into so many problems that revolved around the ARM architecture. That’s when I decided to find a cloud IDE to work on. A long time ago, I used Michael Hartl’s rails tutorial where Cloud9 was used. Cloud9 has since been acquired by Amazon Web Services and is incredibly cumbersome to get running now that you have to have an AWS account, spin up (and pay a good chunk of change for) an EC2 instance just to get started. This is when I came across codeanywhere.
Codeanywhere offers a free 7-day trial and has very affordable plans once the trial period is over. If you pay month-to-month, a basic environment is $6/mo. If you opt for the yearly plan, it comes to $4.80/mo. For $57.60 I can have a cloud based IDE ready to go wherever–I’m no longer tied to my one computer and can do some learning and development anywhere.
So, let’s jump into the setup!
Setting up a new container
Once you have signed up for an account, you’re ready create your first container. A container houses your environment that you’ll be developing in. Click on the New Container button to get started.

Next, you’ll be prompted to select one of their predefined templates for your container. Select Ruby and click on the Create button. You can enter a different container name than the randomly generated name in the text box. You can update this later if you want.


Once your container has been configured by codeanywhere, click on the Open IDE button. If your browser blocks popups, you might need to allow the popup the first time.

This will launch codeanywhere’s IDE which appears to be an exact copy of Visual Studio Code. It’s refreshing if you are used to working in VS Code.
Checking versions of installed tools
It’s time to open up the terminal and start checking things out. From the menu at the top of the editor, click Terminal > New Terminal (or use the keyboard shortcut).

In the terminal, check the current versions of Ruby, Rails, Node, Yarn, and NPM.
ruby -v
rails -v
node -v
yarn -v
npm -v

The Ruby container template from codeanywhere had an older version of Rails 6 installed. I ran gem update rails
to install the latest version of the gem.
I was quite happy that, for the most part, everything was already configured and ready for me to start work.
Adding Postgres to the environment
Install Postgres from APT
For my development, I prefer to use Postgres instead of SQLite. I found a doc from codeanywhere that was helpful to get things up and running: https://docs.codeanywhere.com/advanced-topics/databases/install-postgresql
Run the following commands in the terminal window to install Postgres.
sudo apt-get update
sudo apt-get install postgresql postgresql-contrib
A notification will popup in the bottom-right that says “Process is listening on port 5432” when Postgres has been installed.

Install the Postgres client library
If you were to create a new rails app that uses postgres, you’ll run into a build error. Fortunately, the error message tells you how to fix the issue.

We’ll run sudo apt install libpq-dev
to install the PostgreSQL client library like the message says.
Create a Postgres user to match codeanywhere
If you were to create a new rails app using Postgres, you’ll run into an error that then role does not exist on the database when you run rails db:create
. Codeanywhere uses a user/role called cabox
.

Create the user by running the following command in the terminal: sudo -u postgres createuser cabox -s

Once the user is created, running rails db:create
is successful.
Create a new Rails 7 app with Postgres database
In your terminal create a new rails app and set Postgres as your database.
rails new new_app -d postgresql
cd new_app
rails db:create
rails s
Now that the server is running, you will see a notification in the bottom-right corner informing you that the “Process is listening on port 3000.” You can click on the Open Preview button to show the preview in the IDE or use the Open Browser button to open the server in a new browser window.

When you do, you’ll see an error message that informs you that you’ll need to add a line to your development.rb file (Config > environments > development.rb).

After you add the line of code to your development.rb file, you restart the server to see the new Rails 7 Home Screen.

Conclusion
Pat yourself on the back–you’re ready to get to work in Ruby on Rails 7 using Postgres on codeanywhere! I am finding that using codeanywhere is a better alternative to fighting with tools that don’t yet support Apple Silicon or the ARM architecture just yet.