# Installing from a subdirectory of Github

**URL:** <https://discourse.julialang.org/t/installing-from-a-subdirectory-of-github/25548>\
**Category:** New to Julia\
**Tags:** package\
**Created:** [June 22, 2019, 5:37pm UTC](https://discourse.julialang.org/t/installing-from-a-subdirectory-of-github/25548 "2019-06-22T17:37:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![pistacliffcho](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pistacliffcho/32/8518_2.png) [@pistacliffcho](https://discourse.julialang.org/u/pistacliffcho)\
**Post date:** [June 22, 2019, 5:37pm UTC](https://discourse.julialang.org/t/installing-from-a-subdirectory-of-github/25548/1 "2019-06-22T17:37:39Z")

</div>

I have a [Julia package on GitHub](https://github.com/pistacliffcho/LatentChannelNetworks) for which I’d like to include installation instructions. However, the Julia code is in a subdirectory of the repo as this repo includes both a Julia and R version of the code.

I can’t figure out how remotely install the package from the subdirectory. My first pass was

```julia
Pkg.add("https://github.com/pistacliffcho/LatentChannelNetworks/tree/master/Julia/LatentChannelNetworks")

```

This leads to a 404 error. Is there a way to specify a subdirectory of a repo?

**EDIT:** I have split up the R and Julia repos so the link above currently is broken.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [June 23, 2019, 5:55am UTC](https://discourse.julialang.org/t/installing-from-a-subdirectory-of-github/25548/2 "2019-06-23T05:55:32Z")

</div>

I don’t have a solution for your problem, but as a workaround, you could `git clone` the repository (in the shell) and then in Julia `pkg> add` or `pkg> dev` the relevant path.

---

<div class="post-metadata">

**Author:** ![Amin\_Yahyaabadi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amin_yahyaabadi/32/9826_2.png) [@Amin\_Yahyaabadi](https://discourse.julialang.org/u/Amin_Yahyaabadi)\
**Post date:** [June 23, 2019, 7:39am UTC](https://discourse.julialang.org/t/installing-from-a-subdirectory-of-github/25548/3 "2019-06-23T07:39:51Z")

</div>

Go here and read using someone elses project:  
[https://julialang.github.io/Pkg.jl/v1/environments/#Using-someone-else’s-project-1](https://julialang.github.io/Pkg.jl/v1/environments/#Using-someone-else's-project-1)  
download and clone the project.  
In Julia then:

```julia
cd("clonePath")
]activate .
]instantiate

```

Also try this it may work:

`Pkg.clone("https://github.com/pistacliffcho/LatentChannelNetworks/tree/master/Julia/LatentChannelNetworks")`  
You can include a package name as the second argument.  
`Pkg.clone("https://github.com/pistacliffcho/LatentChannelNetworks/tree/master/Julia/LatentChannelNetworks","packageName")`

---

<div class="post-metadata">

**Author:** ![pistacliffcho](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pistacliffcho/32/8518_2.png) [@pistacliffcho](https://discourse.julialang.org/u/pistacliffcho)\
**Post date:** [June 23, 2019, 3:53pm UTC](https://discourse.julialang.org/t/installing-from-a-subdirectory-of-github/25548/4 "2019-06-23T15:53:51Z")

</div>

Thanks for the suggestions.

I think best practices is going to be split up the repo into an R and Julia implementation. I think it’s a bit sub-optimal to have a user clone a bunch of code they don’t want (i.e. R version) and then muck around with a subdirectory of the repo, rather than just call `Pkg.add("blahblah")`.

---

<div class="post-metadata">

**Author:** ![racinmat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/racinmat/32/11715_2.png) [@racinmat](https://discourse.julialang.org/u/racinmat)\
**Post date:** [July 16, 2021, 11:21am UTC](https://discourse.julialang.org/t/installing-from-a-subdirectory-of-github/25548/5 "2021-07-16T11:21:20Z")

</div>

Now, the

```julia
using Pkg
Pkg.add(PackageSpec(url="https://github.com/pistacliffcho/LatentChannelNetworks.git", subdir="Julia/LatentChannelNetworks"))

```

should be working, since [add subdir functionality by KristofferC · Pull Request #1422 · JuliaLang/Pkg.jl · GitHub](https://github.com/JuliaLang/Pkg.jl/pull/1422)  
but I haven’t tried it for nested subdirectories. It works on single subdir without further nesting, for me.  
The monorepo/subdirectory should be fully supported by the Pkg.jl and the whole package registry by now.

---

<div class="post-metadata">

**Author:** ![bert](https://avatars.discourse-cdn.com/v4/letter/b/9e8a1a/32.png) [@bert](https://discourse.julialang.org/u/bert)\
**Post date:** [August 23, 2022, 6:50pm UTC](https://discourse.julialang.org/t/installing-from-a-subdirectory-of-github/25548/6 "2022-08-23T18:50:23Z")

</div>

You can also use the following syntax in the REPL:

`pkg> add http://github.com/user/repo#rev:path/to/subfolder`

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [August 23, 2022, 7:39pm UTC](https://discourse.julialang.org/t/installing-from-a-subdirectory-of-github/25548/7 "2022-08-23T19:39:57Z")

</div>

This is now listed in the `?Pkg.add` examples:

```julia
help?> Pkg.add
  Pkg.add(pkg::Union{String, Vector{String}}; preserve=PRESERVE_TIERED)
  Pkg.add(pkg::Union{PackageSpec, Vector{PackageSpec}}; preserve=PRESERVE_TIERED)
...
Pkg.add(url="https://github.com/Company/MonoRepo", subdir="juliapkgs/Package.jl)") # With subdir

```

The keywords are forwarded to `PackageSpec`.
