# Removing and adding packages

**URL:** <https://discourse.julialang.org/t/removing-and-adding-packages/18537>\
**Category:** General Usage\
**Tags:** question, package\
**Created:** [December 10, 2018, 8:25pm UTC](https://discourse.julialang.org/t/removing-and-adding-packages/18537 "2018-12-10T20:25:53Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [December 10, 2018, 8:25pm UTC](https://discourse.julialang.org/t/removing-and-adding-packages/18537/1 "2018-12-10T20:25:53Z")

</div>

If I manually remove a package directory from the repository I cannot normally install it. Example:

Step 1. I manually removed package directory from `~/.julia/packages/DataFrames/`  
Step 2. I try to install it using `add DataFrames`. I get an error:

```julia
(v1.0) pkg> add DataFrames
 Resolving package versions...
ERROR: path ~/.julia/packages/DataFrames/KUWId for package DataFrames no longer exists. Remove the package or `develop` it at a new path

```

Step 3. I remove the package `(v1.0) pkg> rm DataFrames` - all seems fine.

Step 4. I try to add the package `(v1.0) pkg> add DataFrames` and get the same error

Step 5. I try to add the package master: `(v1.0) pkg> add DataFrames#master` - now it works

Would it be possible to make `(v1.0) pkg> add DataFrames` work?

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [December 10, 2018, 9:47pm UTC](https://discourse.julialang.org/t/removing-and-adding-packages/18537/2 "2018-12-10T21:47:12Z")

</div>

Maybe [Second Pkg.add for branch revision fails · Issue #913 · JuliaLang/Pkg.jl · GitHub](https://github.com/JuliaLang/Pkg.jl/issues/913) (fix incoming with Julia 1.0.3) although that only applied to adding with a branch multiple times. You get this from just a regular `add DataFrames`?

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [December 10, 2018, 10:00pm UTC](https://discourse.julialang.org/t/removing-and-adding-packages/18537/3 "2018-12-10T22:00:45Z")

</div>

Yes - it seems that `add DataFrames` expects the folder to exist if it was manually removed, but e.g. `add DataFrames#master` creates the folder so it works.

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [December 10, 2018, 10:35pm UTC](https://discourse.julialang.org/t/removing-and-adding-packages/18537/4 "2018-12-10T22:35:02Z")

</div>

I can not reproduce this.

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [December 11, 2018, 8:02am UTC](https://discourse.julialang.org/t/removing-and-adding-packages/18537/5 "2018-12-11T08:02:49Z")

</div>

Thank you for investigating into it. Here are detailed instructions how you can reproduce it.  
Current version of DataFrames 0.15.2 installs in `~/.julia/packages/DataFrames/KUWId`.

1. Run `add DataFrames#master`
2. Delete `~/.julia/packages/DataFrames/KUWId` folder
3. Run `add DataFrames` (without master) - you get the error
4. Run `rm DataFrames` - seems to work
5. Run `add DataFrames` (without master) - you get the same error still
6. Run `add DataFrames#master` - now it is OK

And a second way (more problematic in my opinion):

1. Run `add DataFrames#master`
2. Run `rm DataFrames` - removes the package from the registry
3. Delete `~/.julia/packages/DataFrames/KUWId` folder - it should be OK (the package is not installed now)
4. Run `add DataFrames` - you get an error, although you try to “freshly” install the package
5. Now create `~/.julia/packages/DataFrames/KUWId` folder (it is empty)
6. Run `add DataFrames` - Julia tells you that `DataFrames v0.15.2+ #master` is installed (although I did not ask for `master`) and what is more `~/.julia/packages/DataFrames/KUWId`is still empty (although last command went through without a problem informing me that the installation was successfull)

Additionally I have the following question I stumbled when writing down the steps to reproduce the above:

1. Run `add DataFrames`
2. Delete file `~/.julia/packages/DataFrames/KUWId/src/DataFrames.jl`
3. Now the package is corrupded, so I try running `add DataFrames` to fix the corrupted state, but actually the folder `~/.julia/packages/DataFrames/KUWId` does not get fixed

---

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [December 11, 2018, 8:22am UTC](https://discourse.julialang.org/t/removing-and-adding-packages/18537/6 "2018-12-11T08:22:25Z")

</div>

FWIW, I observed a similar issue when `] up SomePackage`. However, somewhat strangely it always worked the second time (exact same command, i.e. `] up SomePackage`).

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [December 11, 2018, 8:53am UTC](https://discourse.julialang.org/t/removing-and-adding-packages/18537/7 "2018-12-11T08:53:32Z")

</div>

In general it seems to me that the Package Manager probably caches something and then uses this information again when processing the commands.  
Probably this is needed to ensure responsiveness (and this is great in comparison to an old package manager). But maybe:

- there are some checks that are cheap and could be done
- you could have a switch that forces the Package Manager to be in a “defensive” mode and check everything when running the command

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [December 11, 2018, 8:53am UTC](https://discourse.julialang.org/t/removing-and-adding-packages/18537/8 "2018-12-11T08:53:37Z")

</div>

Ok, this is definitely [Second Pkg.add for branch revision fails · Issue #913 · JuliaLang/Pkg.jl · GitHub](https://github.com/JuliaLang/Pkg.jl/issues/913) then.

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [December 11, 2018, 8:57am UTC](https://discourse.julialang.org/t/removing-and-adding-packages/18537/9 "2018-12-11T08:57:08Z")

</div>

> [@bkamins](#):
>
> Additionally I have the following question I stumbled when writing down the steps to reproduce the above:
> 
> 1. Run `add DataFrames`
> 2. Delete file `~/.julia/packages/DataFrames/KUWId/src/DataFrames.jl`
> 3. Now the package is corrupded, so I try running `add DataFrames` to fix the corrupted state, but actually the folder `~/.julia/packages/DataFrames/KUWId` does not get fixed

Well, the files are write-protected, so you have to go to some length to actually remove files like this. But perhaps checking for the entry file makes sense, but since we can’t know if any other files have been removed I am not surehow much it helps to check for one file.

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [December 11, 2018, 9:08am UTC](https://discourse.julialang.org/t/removing-and-adding-packages/18537/10 "2018-12-11T09:08:14Z")

</div>

On Windows they are not write-protected ☹ (and I must admit with shame that sometimes I dabble with the repo if I have to make a quick-hack and I am to lazy to run `develop`).

A strategy could be e.g. to have a fingerprint of the state of the repository and checking if it has not changed (and if it changed then we know that the folder is corrupted). For most packages this should be quick (but if it happens to be slow then as I have proposed above there should be some option for turning on strict checking on demand).

Anyway - thank you for [https://github.com/JuliaLang/Pkg.jl/issues/913](https://github.com/JuliaLang/Pkg.jl/issues/913) as hopefully this will solve most of the problems. What I am writing above is nice-to-have only, as this is normally not strictly required.

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [December 11, 2018, 9:17am UTC](https://discourse.julialang.org/t/removing-and-adding-packages/18537/11 "2018-12-11T09:17:46Z")

</div>

There is actually another problem here. The problems described above is only partially fixed by #913.

> [@bkamins](#):
>
> On Windows they are not write-protected

Hmm, seems like a bug then, the `chmod` calls here [https://github.com/JuliaLang/Pkg.jl/blob/2075b74621f7829a930a480fe4c3b8c8f8ac0924/src/Operations.jl#L65-L74](https://github.com/JuliaLang/Pkg.jl/blob/2075b74621f7829a930a480fe4c3b8c8f8ac0924/src/Operations.jl#L65-L74) should set the file permission. Does that not happend? (This requires Julia 1.0.2 btw).

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [December 11, 2018, 9:19am UTC](https://discourse.julialang.org/t/removing-and-adding-packages/18537/12 "2018-12-11T09:19:20Z")

</div>

I am on Julia 1.0.2 but I have admin privilleges on my laptop.
