DEV Community

Cover image for rmate with sudo
Uğur "vigo" Özyılmazel
Uğur "vigo" Özyılmazel

Posted on

rmate with sudo

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.

TextMate > Settings > Terminal

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

Save and exit from nano. Now install rmate:

gem install --user-install rmate
Enter fullscreen mode Exit fullscreen mode

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

sudo visudo
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

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

sudo -E rmate /etc/nginx/nginx.conf
Enter fullscreen mode Exit fullscreen mode

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

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

Top comments (0)