diff --git a/src/app/handlers/xdgurl.cpp b/src/app/handlers/xdgurl.cpp
index f4f492f86b91e530478998142a82da268d0e327b..b426947ee112b71df6815380bc06e2aca6728875 100644
--- a/src/app/handlers/xdgurl.cpp
+++ b/src/app/handlers/xdgurl.cpp
@@ -201,8 +201,6 @@ void XdgUrl::installDownloadedFile(qtlibs::NetworkResource *resource)
         return;
     }
 
-    qtlibs::Package package(tempPath);
-
     QString type = metadata_["type"].toString();
     QString destination = destinations_[type].toString();
     QString path = destination + "/" + metadata_["filename"].toString();
@@ -210,6 +208,9 @@ void XdgUrl::installDownloadedFile(qtlibs::NetworkResource *resource)
     qtlibs::Dir(destination).make();
     qtlibs::File(path).remove(); // Remove previous downloaded file
 
+    qtlibs::File tempFile(tempPath);
+    qtlibs::Package package(tempPath);
+
     if (type == "bin"
             && package.installAsProgram(path)) {
         result["message"] = QString("The file has been installed into " + destination);
@@ -245,12 +246,15 @@ void XdgUrl::installDownloadedFile(qtlibs::NetworkResource *resource)
         result["message"] = QString("The file has been installed into " + destination);
     }
     else {
+        tempFile.remove();
         result["status"] = QString("error_install");
         result["message"] = QString("Failed to installation");
         emit error(result);
         return;
     }
 
+    tempFile.remove();
+
     destination_ = destination;
 
     result["status"] = QString("success_install");