DEV Community

Gaurav Makwana
Gaurav Makwana

Posted on

Effortless Ruby on Rails Development on EC2 Server with VS Code Remote SSH

If you are a Ruby on Rails developer, chances are you may need to work on projects hosted on an EC2 server on Amazon Web Services (AWS) or any other cloud platform. Managing code, running commands, and debugging remotely can be challenging, but with the VS Code Remote SSH feature, you can streamline your workflow and code efficiently on your EC2 server with the same convenience as your local setup.

Here’s a step-by-step example of how you can set up VS Code Remote SSH to work on a Ruby on Rails project hosted on an EC2 server:

Prerequisites
An EC2 instance running with Ruby, Rails, and other dependencies installed.
Install VSCode on your local system and the VSCode Remote Development extension pack from the Visual Studio Code Marketplace at https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack.
Connect to your EC2 server

In VS Code, press Ctrl+Shift+P (Cmd+Shift+P on macOS) to open the Command Palette, type “Remote-SSH: Connect to Host” and select it. Enter the SSH connection details of your EC2 server, including the hostname or IP address, the username (usually “ec2-user” for AWS EC2 instances), and the path to your private key file. Click “Connect” to establish an SSH connection to your EC2 server.
Install the necessary extensions: Once connected to your EC2 server, you may need to install additional VS Code extensions for Ruby and Rails development, such as Ruby, Rails, and Ruby Language Server. You can install these extensions from the Extensions Marketplace within VS Code.

Working with VS Code Remote SSH

Editing files: Open the files of your Ruby on Rails project on your EC2 server in VS Code, and start making edits. VS Code will automatically save the changes remotely.

Running commands: Open the integrated terminal in VS Code by clicking on “Terminal” in the top menu and selecting “New Terminal”. You can then run commands, such as running rails c to interact with the database.

Debugging: You can also debug your Ruby on Rails code on your EC2 server using VS Code Remote SSH. Set breakpoints, inspect variables, and step through the code, just like you would when debugging locally also such as restarting the Nginx service with “sudo nginx service restart” directly from your local VSCode instance.

Benefits of VS Code Remote SSH for Ruby on Rails Development on EC2

Productivity: Use familiar code editing features, shortcuts, and settings.
Flexibility: Works with Linux, macOS, or Windows, regardless of your local machine’s OS.
Collaboration: Enable real-time collaboration with other developers on remote machines.

Conclusion
VS Code Remote SSH is a powerful tool for seamless Ruby on Rails development on EC2 servers, enhancing productivity, ensuring security, offering flexibility, and enabling collaboration. Give it a try for convenient and efficient remote development with VS Code.

Top comments (0)