How to properly set up a formatter for Vagrantfiles in VS Code?
09:20 25 Dec 2025

Problem: I am using VS Code to edit Vagrantfile (Ruby syntax). By default, VS Code does not format these files correctly. When I install recommended Ruby extension like Ruby LSP, nothing happens when select "Format document".

Other extensions like Rufo, RuboCop, or Standard Ruby.. I get stuck in a "dependency hell" of error messages, including but not limited to:

  • Failed to setup the bundle
  • Gem::FilePermissionError (write permissions for /var/lib/gems/)
  • bundle: not found
  • couldn't find rufo for formatting (ENOENT)

Goal: I am looking for a "Plug and Play" way to get standard Ruby indentation/formatting in my Vagrantfile without having to manage a complex Ruby environment, Gemfiles, or system-level Ruby permissions.

Environment:

  • Ubuntu: 24.04
  • Ruby: 3.2.3
  • Default Formatter: Prettier (which doesn't seem to support Ruby out of the box)
ruby visual-studio-code vscode-extensions vagrantfile ruby-lsp