# Can I install an executable in $PREFIX/bin using Pkg?

**URL:** https://discourse.julialang.org/t/can-i-install-an-executable-in-prefix-bin-using-pkg/20128
**Category:** New to Julia
**Created:** [January 26, 2019, 3:35pm UTC](https://discourse.julialang.org/t/can-i-install-an-executable-in-prefix-bin-using-pkg/20128 "2019-01-26T15:35:27Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![ninjaaron](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ninjaaron/32/6392_2.png) [@ninjaaron](https://discourse.julialang.org/u/ninjaaron)
#### Post date: [January 26, 2019, 3:35pm UTC](https://discourse.julialang.org/t/can-i-install-an-executable-in-prefix-bin-using-pkg/20128/1 "2019-01-26T15:35:27Z")

</div>

So, in Python, there is a notion of “entry\_points” for your package that are scripts which are installed where ever your system looks for executables.

Is this possible with Pkg?

---

<div class="post-metadata">

### Author: ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)
#### Post date: [January 26, 2019, 5:57pm UTC](https://discourse.julialang.org/t/can-i-install-an-executable-in-prefix-bin-using-pkg/20128/2 "2019-01-26T17:57:44Z")

</div>

You could perform the installation in your package’s `deps/build.jl` file, which gets run whenever your package is built. Unfortunately I don’t know if there’s any way to automatically clean up the installed file when your package is removed.

---

<div class="post-metadata">

### Author: ![ninjaaron](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ninjaaron/32/6392_2.png) [@ninjaaron](https://discourse.julialang.org/u/ninjaaron)
#### Post date: [January 26, 2019, 6:14pm UTC](https://discourse.julialang.org/t/can-i-install-an-executable-in-prefix-bin-using-pkg/20128/3 "2019-01-26T18:14:21Z")

</div>

Thanks for the reply. I’ll try to do a deepdive on Pkg one of these days and see if I can’t get something working.

---

<div class="post-metadata">

### Author: ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)
#### Post date: [January 26, 2019, 7:54pm UTC](https://discourse.julialang.org/t/can-i-install-an-executable-in-prefix-bin-using-pkg/20128/4 "2019-01-26T19:54:27Z")

</div>

For example, if you have an executable inside your package’s `deps` folder called `foo`, you could write a `deps/build.jl` file that looks like this:

```julia
# deps/build.jl

symlink(joinpath(@ __DIR__ , "foo"), "/usr/local/bin/foo")

```

That will automatically create the symlink whenever you do `pkg> add MyPackage` and/or `pkg> build MyPackage`. Of course, this assumes that `foo` is compatible with the current operating system and that `/usr/local/bin/` is on the path, so your script will probably need to be more complicated if those assumptions don’t hold in your particular use case.

---

<div class="post-metadata">

### Author: ![ninjaaron](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ninjaaron/32/6392_2.png) [@ninjaaron](https://discourse.julialang.org/u/ninjaaron)
#### Post date: [January 26, 2019, 7:58pm UTC](https://discourse.julialang.org/t/can-i-install-an-executable-in-prefix-bin-using-pkg/20128/5 "2019-01-26T19:58:46Z")

</div>

I’ll look at that. I was thinking something more along the lines of a pull-request on Pkg itself that adds support for cross-platform script install and removal, but it may be that my eyes are bigger than my stomach on this one. Probably should start with my own package that integrates with Pkg and see how it goes.

---

<div class="post-metadata">

### Author: ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)
#### Post date: [January 27, 2019, 3:01am UTC](https://discourse.julialang.org/t/can-i-install-an-executable-in-prefix-bin-using-pkg/20128/6 "2019-01-27T03:01:03Z")

</div>

Unlike Python, project environment in Julia does not have a dedicated `$PREFIX` directory (it’s just two TOML files). So I think it’s a bit tricky to install executables. But I can imagine an API that would copy scripts to `$PROJECT/bin` (say) where `$PROJECT` is the directory you have `Project.toml`. It means that users have to explicitly add, e.g., `~/.julia/environments/v1.1/bin` to the `PATH`. But since there can be multiple Julia versions and multiple environments, I think it’s much safer option.

Another idea: I think you can just write a separate helper package (say) `ScriptInstaller` based on `Pkg` for installing and managing Julia scripts in `~/.local/bin/` (and other places in other OSes). The installed script can keep the path to Julia project and `julia` executable. Users would run `ScriptInstaller.add("PACKAGE")` which creates a dedicated project, runs `Pkg.add("PACKAGE")` in it, and then finally install the entry points to `~/.local/bin/` etc.

---

<div class="post-metadata">

### Author: ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)
#### Post date: [January 27, 2019, 3:40am UTC](https://discourse.julialang.org/t/can-i-install-an-executable-in-prefix-bin-using-pkg/20128/7 "2019-01-27T03:40:42Z")

</div>

> [@rdeits](#):
>
> Unfortunately I don’t know if there’s any way to automatically clean up the installed file when your package is removed.

There is a way, the package manager could be looking for a `deps/clean.jl` script.

---

<div class="post-metadata">

### Author: ![ninjaaron](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ninjaaron/32/6392_2.png) [@ninjaaron](https://discourse.julialang.org/u/ninjaaron)
#### Post date: [January 27, 2019, 8:47am UTC](https://discourse.julialang.org/t/can-i-install-an-executable-in-prefix-bin-using-pkg/20128/8 "2019-01-27T08:47:25Z")

</div>

> [@tkf](#):
>
> Another idea: I think you can just write a separate helper package (say) `ScriptInstaller` based on `Pkg` for installing and managing Julia scripts in `~/.local/bin/` (and other places in other OSes). The installed script can keep the path to Julia project and `julia` executable. Users would run `ScriptInstaller.add("PACKAGE")` which creates a dedicated project, runs `Pkg.add("PACKAGE")` in it, and then finally install the entry points to `~/.local/bin/` etc.

I was thinking something along these lines. It’s not a complete application distribution system, but a way to distribute executables with Julia packages would be a step in the right direction in my book.

---

<div class="post-metadata">

### Author: ![daniel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/daniel/32/6480_2.png) [@daniel](https://discourse.julialang.org/u/daniel)
#### Post date: [January 27, 2019, 11:59pm UTC](https://discourse.julialang.org/t/can-i-install-an-executable-in-prefix-bin-using-pkg/20128/9 "2019-01-27T23:59:19Z")

</div>

Have you heard about BinaryBuilder.jl ? It seems like the perfect usecase for your scenario. Here is a youtube link for a nice explanation: [JuliaCon 2018 | 10 tips on how to build better binaries | Elliot Saba - YouTube](https://www.youtube.com/watch?v=2e0PBGSaQaI)

---

<div class="post-metadata">

### Author: ![ninjaaron](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ninjaaron/32/6392_2.png) [@ninjaaron](https://discourse.julialang.org/u/ninjaaron)
#### Post date: [January 28, 2019, 12:07am UTC](https://discourse.julialang.org/t/can-i-install-an-executable-in-prefix-bin-using-pkg/20128/10 "2019-01-28T00:07:58Z")

</div>

I’m not thinking of binaries, just installing little uncompiled Julia executables somewhere in the user’s $PATH in a manor similar to what Python packages and Ruby gems do.

This is mostly just for my personal use. I have a lot of little python modules with helper scripts attached that like to install all over the place.

However, maybe binaries would be even better? I’ll look at this package, in any case.

---

<div class="post-metadata">

### Author: ![daniel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/daniel/32/6480_2.png) [@daniel](https://discourse.julialang.org/u/daniel)
#### Post date: [January 28, 2019, 12:48am UTC](https://discourse.julialang.org/t/can-i-install-an-executable-in-prefix-bin-using-pkg/20128/11 "2019-01-28T00:48:50Z")

</div>

Ah, in that case my answer wasn’t helpful. BinaryBuilder (+BinaryProvider) is for making binaries and libraries available for your package.

If you’re just looking for a convenient way to run your julia script from the command line I’d just create a simple bash variable and call julia with something like `julia -E "using Test; @test 1 == 1"`

---

<div class="post-metadata">

### Author: ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)
#### Post date: [January 28, 2019, 1:15am UTC](https://discourse.julialang.org/t/can-i-install-an-executable-in-prefix-bin-using-pkg/20128/12 "2019-01-28T01:15:01Z")

</div>

I think `build_executable` from [PackageCompiler.jl](https://github.com/JuliaLang/PackageCompiler.jl) can in principle do this. There is also [ApplicationBuilder.jl](https://github.com/NHDaly/ApplicationBuilder.jl) (see [JuliaCon 2018 | Julia apps on the App Store | Nathan Daly - YouTube](https://www.youtube.com/watch?v=kSp6d3qSb3I)).

---

<div class="post-metadata">

### Author: ![taqtiqa-mark](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/taqtiqa-mark/32/4383_2.png) [@taqtiqa-mark](https://discourse.julialang.org/u/taqtiqa-mark)
#### Post date: [November 4, 2019, 12:18am UTC](https://discourse.julialang.org/t/can-i-install-an-executable-in-prefix-bin-using-pkg/20128/13 "2019-11-04T00:18:50Z")

</div>

> [@ninjaaron](#):
>
> I’m not thinking of binaries, just installing little uncompiled Julia executables somewhere in the user’s $PATH in a manor similar to what Python packages and Ruby gems do.

@ninjaaron I think the [jlenv org](https://www.github.com/jlenv) might be of interest to you? One of the tools is jlenv - a port of the rbnev/pyenv tools. That said the use of binstubs in Julia seems relatively limited, so there maybe sharp edges when using these tools.

The [jlenv org](https://www.github.com/jlenv) contains a collection projects addressing the various use cases that give rise to needing to switch between different versions of Julia.

The [announcement](https://discourse.julialang.org/t/ann-julia-build-jlenv-jlenv-plugins-and-jlenv-cookbook/30528) in the Tools forum has more details.
