rmate with sudo



This content originally appeared on DEV Community and was authored by Uğur “vigo” Özyılmazel

I honestly don’t know if there are still any dinosaurs like me using TextMate
in 2025. But if you’re a die-hard TextMate fan like I am, then I’ve got some
exciting news for you. Have you ever heard of rmate?

rmate is actually a Ruby gem. What does it do? It lets you open a file from
a remote server (via SSH) directly in your local TextMate editor—just as if
you had run mate /path/to/file on your own machine.

In TextMate, under Settings > Terminal, there’s an option called Accept rmate connections—make sure that’s checked first.

Next, connect to your VPS via SSH and install Ruby, followed by rmate, using the commands below. Let’s assume you’re using Ubuntu as your VPS operating system:

sudo apt install ruby -y

Now, find the location for user installation directory for
ruby gems:

gem environment | grep "USER INSTALLATION DIRECTORY" | awk -F': ' '{print $2}'
# something like:
# /home/ubuntu/.local/share/gem/ruby/3.2.0/bin

Now, edit your ~/.bashrc and add this path to your PATH environment
variable:

# set PATH if local ruby gems bin exists
PATH="${PATH}:${HOME}/.local/share/gem/ruby/3.2.0/bin"

Save and exit from nano. Now install rmate:

gem install --user-install rmate

Now, restart your shell, logout/login works fine. Now run:

sudo visudo

Edit your sudo configuration, Two changes, add env_keep and append
/home/ubuntu/.local/share/gem/ruby/3.2.0/bin to secure_path under the line
of Defaults env_reset:

Defaults        env_reset
Defaults        env_keep +="RMATE_HOST"
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/home/ubuntu/.local/share/gem/ruby/3.2.0/bin"

Now, restart your shell, logout/login works fine. Now open (as an example):

sudo -E rmate /etc/nginx/nginx.conf

sudo -E does the trick! -E keeps environment variables which are defined
in env_keep.

Thats all! Keep the TextMate spirit alive! (macOS only)


This content originally appeared on DEV Community and was authored by Uğur “vigo” Özyılmazel