arduino/Arduino · error · IOException

Could not remove old version of {0}

Error message

Could not remove old version of {0}

What it means

BaseNoGui's replaceFileToBeInstalled helper throws this IOException when an existing file that is about to be replaced cannot be deleted (File.delete() returned false). Deletion must succeed because the subsequent installation strategy is remove-then-rename.

Source

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

    File temp = File.createTempFile(file.getName(), null, file.getParentFile());
    // Split the file content using minimum common separator \n
    // then trim any other character (\r) so saveStrings can print it in the correct
    // format for every OS
    String strArray[] = str.split("\n");
    for (String item : strArray) {
      item.trim();
    }
    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();

View on GitHub (pinned to a0df6e0e83)

Solutions

  1. Close other Arduino IDE instances and any program locking the target file (antivirus scanners, editors), then retry the install
  2. Run the IDE with sufficient privileges or take ownership of the installation/library directory (chmod/chown or run as admin)
  3. Delete the old file manually and retry the installation
  4. Install into a user-writable sketchbook directory instead of a system location

Example fix

// manual remediation before install
// chmod u+w libraries/MyLib/MyLib.jar && rm libraries/MyLib/MyLib.jar
// then run the library install again
Defensive patterns

Strategy: try-catch

Validate before calling

File old = new File(libDir, "MyLib.jar");
if (old.exists() && (!old.canWrite() || !old.getParentFile().canWrite()))
  throw new IllegalStateException("Cannot delete old version: " + old);

Try / catch

try {
  installer.install(lib, replaceMode);
} catch (IOException e) {
  if (e.getMessage().startsWith("Could not remove old version")) {
    // close locking apps, fix permissions, delete manually, retry
  } else throw e;
}

Prevention

When it happens

Trigger: During a library/tool/platform installation, the old version file exists, file.delete() returns false (file locked, read-only, or permission denied), so the old version cannot be removed before renameTo() of the temp copy.

Common situations: Windows file locking (antivirus/another IDE instance holds the jar); installing into a directory owned by root or another user; file marked read-only; SAMBA/NFS share without delete permission.

Related errors


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