arduino/Arduino · error · IOException

Could not replace {0}

Error message

Could not replace {0}

What it means

BaseNoGui's replaceFileToBeInstalled throws this IOException when the downloaded temp file cannot be renamed onto the target path (temp.renameTo(file) returned false) after the old version was removed. renameTo() fails silently for cross-filesystem moves or when the target is locked.

Source

Thrown at arduino-core/src/processing/app/BaseNoGui.java:912

    PApplet.saveStrings(temp, strArray);

    try {
      file = file.toPath().toRealPath().toFile().getCanonicalFile();
    } catch (IOException e) {
    }

    if (file.exists()) {
      boolean result = file.delete();
      if (!result) {
        throw new IOException(
      I18n.format(
        tr("Could not remove old version of {0}"),
        file.getAbsolutePath()));
      }
    }
    boolean result = temp.renameTo(file);
    if (!result) {
      throw new IOException(
    I18n.format(
      tr("Could not replace {0}"),
      file.getAbsolutePath()));
    }
  }

  static public void selectBoard(TargetBoard targetBoard) {
    TargetPlatform targetPlatform = targetBoard.getContainerPlatform();
    TargetPackage targetPackage = targetPlatform.getContainerPackage();

    PreferencesData.set("target_package", targetPackage.getId());
    PreferencesData.set("target_platform", targetPlatform.getId());
    PreferencesData.set("board", targetBoard.getId());

    File platformFolder = targetPlatform.getFolder();
    PreferencesData.set("runtime.platform.path", platformFolder.getAbsolutePath());
    PreferencesData.set("runtime.hardware.path", platformFolder.getParentFile().getAbsolutePath());
  }

View on GitHub (pinned to a0df6e0e83)

Solutions

  1. Ensure the temp directory and target directory are on the same filesystem (e.g. set temp files next to the destination, or move TMPDIR onto the same volume)
  2. Close programs locking the destination (IDE instances, antivirus) and retry
  3. Run with write permission on the destination (fix ownership or install to the user sketchbook)
  4. If implementing, replace renameTo with a copy+delete fallback (java.nio.file.Files.move with REPLACE_EXISTING)

Example fix

// before: renameTo fails across filesystems
boolean result = temp.renameTo(file);
if (!result) throw ...;
// after: robust move
java.nio.file.Files.move(temp.toPath(), file.toPath(),
  java.nio.file.StandardCopyOption.REPLACE_EXISTING,
  java.nio.file.StandardCopyOption.ATOMIC_MOVE); // or fall back to copy+delete
Defensive patterns

Strategy: fallback

Validate before calling

String tempFs = temp.toPath().toAbsolutePath().getRoot().toString();
String destFs = file.toPath().toAbsolutePath().getRoot().toString();
if (!tempFs.equals(destFs)) throw new IllegalStateException("Temp and target on different volumes");

Try / catch

try {
  installer.install(lib, replaceMode);
} catch (IOException e) {
  if (e.getMessage().startsWith("Could not replace")) {
    // destination locked or cross-volume; fix TMPDIR or close locking apps and retry
  } else throw e;
}

Prevention

When it happens

Trigger: Installation of a library/tool: after deleting the old file, temp.renameTo(file) returns false — typically because temp and file live on different filesystems/mount points, or the destination is locked/undeletable in practice.

Common situations: Temp directory on a different drive/partition than the sketchbook (common on Windows or with TMPDIR overrides); antivirus locking the destination; installing to a read-only or admin-owned directory.

Related errors


AI-assisted analysis of arduino/Arduino@a0df6e0e83 (2026-09-06). Data as JSON: /api/errors/9299a2a791a7abfb. Report an issue: GitHub.