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
- Close other Arduino IDE instances and any program locking the target file (antivirus scanners, editors), then retry the install
- Run the IDE with sufficient privileges or take ownership of the installation/library directory (chmod/chown or run as admin)
- Delete the old file manually and retry the installation
- 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
- Install into a user-writable sketchbook directory, not system paths
- Close other IDE instances and exclude the IDE dirs from antivirus locks
- Remove read-only flags from library/tool files before upgrading
- On Linux keep consistent ownership of the sketchbook directory
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
- Could not create folder: {outputFile}
- Could not replace {0}
- Failed to rename sketch folder
- Could not create directory "{0}"
- Failed to rename "{0}" to "{1}"
AI-assisted analysis of arduino/Arduino@a0df6e0e83 (2026-09-06).
Data as JSON: /api/errors/7405c7782b092e78.
Report an issue: GitHub.