hashicorp/vagrant · error · Vagrant::Errors::LocalDataDirectoryNotAccessible

The directory Vagrant will use to store local environment-sp

Error message

The directory Vagrant will use to store local environment-specific
state is not accessible. The directory specified as the local data
directory must be both readable and writable for the user that is
running Vagrant.

Local data directory: %{local_data_path}

What it means

Raised as Vagrant::Errors::LocalDataDirectoryNotAccessible from setup_local_data_path (lib/vagrant/environment.rb:957) when FileUtils.mkdir_p(@local_data_path) — the project's .vagrant/ directory (or VAGRANT_DOTFILE_PATH target) — or the rgloader loader.rb copy into it raises Errno::EACCES.

Source

Thrown at lib/vagrant/environment.rb:957

      if @local_data_path.file?
        upgrade_v1_dotfile(@local_data_path)
      end

      # If we don't have a root path, we don't setup anything
      return if !force && root_path.nil?

      begin
        @logger.debug("Creating: #{@local_data_path}")
        FileUtils.mkdir_p(@local_data_path)
        # Create the rgloader/loader file so we can use encoded files.
        loader_file = @local_data_path.join("rgloader", "loader.rb")
        if !loader_file.file?
          source_loader = Vagrant.source_root.join("templates/rgloader.rb")
          FileUtils.mkdir_p(@local_data_path.join("rgloader").to_s)
          FileUtils.cp(source_loader.to_s, loader_file.to_s)
        end
      rescue Errno::EACCES
        raise Errors::LocalDataDirectoryNotAccessible,
          local_data_path: @local_data_path.to_s
      end
    end

    protected

    # Attempt to guess the configured provider in use. Will fallback
    # to the default provider if an explicit provider name is not
    # provided. This can be pretty error prone, but is used during
    # initial environment setup to allow loading plugins so it doesn't
    # need to be perfect
    #
    # @return [String]
    def guess_provider
      gp = nil
      ARGV.each_with_index do |val, idx|
        if val.start_with?("--provider=")
          gp = val.split("=", 2).last

View on GitHub (pinned to 35f3160f4a)

Solutions

  1. Inspect `ls -ld . .vagrant` — if .vagrant is root-owned and its state is expendable, `sudo rm -rf .vagrant` and let Vagrant recreate it (machines re-sync on next `vagrant up`)
  2. Otherwise fix ownership: `sudo chown -R $(id -u):$(id -g) .vagrant`
  3. Ensure the parent project directory itself is writable by your user, and relocate projects out of root-owned paths
  4. Never alternate sudo and non-sudo vagrant in the same project directory

Example fix

# before
$ ls -ld .vagrant
drwxr-xr-x 1 root root ... .vagrant
$ vagrant up   # LocalDataDirectoryNotAccessible

# after
$ sudo chown -R $(id -u):$(id -g) .vagrant
$ vagrant up
Defensive patterns

Strategy: validation

Validate before calling

local = ENV["VAGRANT_DOTFILE_PATH"] || File.join(Dir.pwd, ".vagrant")
parent = File.dirname(local)
raise ArgumentError, "cannot create local data dir #{local}" unless File.writable?(parent)
raise ArgumentError, "local data dir #{local} not writable" if File.exist?(local) && !File.writable?(local)

Try / catch

begin
  env = Vagrant::Environment.new(cwd: project_dir)
rescue Vagrant::Errors::LocalDataDirectoryNotAccessible => e
  abort "Fix ownership of #{e.extra_data[:local_data_path]} (chown to $(id -u)) or its parent"
end

Prevention

When it happens

Trigger: The project directory or an existing .vagrant directory is owned by root because a previous `sudo vagrant` ran there; the project lives under a root-owned checkout (e.g. /opt) or on a read-only mount, so the current user cannot create/write .vagrant.

Common situations: Mixed sudo/non-sudo usage in one project (root-owned .vagrant); repositories cloned into system paths; NFS/SMB mounts with permission mismatches between guest and host users.

Understand the failure class

Background: Permission denied / not authorized / 403 Forbidden: access-control rejections when the caller lacks the required role, grant, or ownership — this error's family across 18 libraries.

Related errors


AI-assisted analysis of hashicorp/vagrant@35f3160f4a (2026-08-21). Data as JSON: /api/errors/fa278a867e674635. Report an issue: GitHub.