localinstall/README.md

111 lines
3.9 KiB
Markdown
Raw Permalink Normal View History

2021-11-23 00:30:24 -08:00
# NOTE: I have been enlightened by `pkgsrc`
This script was originally my own hacky way of locally installing
things that I built from source or things that I generally did not
want polluting my system's `/bin` directories. I recently found out
about `pkgsrc`, and that has since replaced my need for this script
with very few exceptions. There are certain things that are not
available in `pkgsrc`, and other times you may want to build the
latest `trunk/master/main` version instead of the stable release.
http://pkgsrc.org/
2021-08-29 15:58:57 -07:00
# Localinstall
2021-11-23 00:30:24 -08:00
2021-08-29 15:58:57 -07:00
This is a simple script that symlinks files into my `~/.local/bin`
directory. I have this directory already part of my `PATH` environment
variable, so this allows me to effectively "install" stuff for just my
user.
You can use `localinstall.sh` to install itself as a convenient first
step.
```sh
./localinstall.sh ./localinstall.sh
```
Then make sure that your `PATH` is updated to use these binaries. Add
this to your shell init file thing (e.g. `.zshrc` or `.bashrc`):
```sh
PATH=${HOME}/.local/bin:$PATH
```
Then open a new shell (or source your init file again) and you should
be able to call `localinstall.sh` from any directory.
Then lets say you compiled a binary called `my_program`. You can do this
```sh
localinstall.sh ./my_program
```
And now you can call `my_program` from anywhere as well.
## But Why!?
Why the heck would you ever use this? Well...a couple of reasons.
Personally, I don't like it when I have to install stuff into a more
global directory. A lot of programs will default to `/usr/local/bin`,
which seems like the ideal place to put stuff. However, it still needs
`sudo` to install things there, and it installs stuff for all users on
the system. I don't necessarily want other users to use my
development-branch build of a program.
When running `make install` (or similar), some programs don't have a
sane default like `/usr/local/bin` and instead do things like
`/usr/local/<program>` or `/opt/<program>`. I don't think I've ever
seen anything actually plop directly into `/usr/bin` or `/bin`, but
that would be the worst case scenario. This script lets me keep all my
binaries in one place, specifically ones that are not installed by the
system's repository. Related to this, I know where everything is, and
so they are easier to cleanup or uninstall later. Some programs don't
properly implement `make uninstall`.
I don't typically have other users on my systems, just me. So
installing globally for all users vs just my user is kinda moot.
I also don't always want all of the things to be installed from a
software package. Running `make install` may place a whole collection
of binaries into my system when I really only wanted 1 of them. This
lets me just symlink the one I needed.
## Limitations
As kinda outlined in the "why" section, using this script has some
limitations/properties:
* These are only installed for the user that ran the script.
* The thing pointed to by each symlink can change out from under you.
2021-09-07 22:19:42 -07:00
## Alternatives
I may have finally found a more "correct" alternative to this where I
actually used `~/usr/local` as my install prefix. I always found it
annoying that I couldn't change an install prefix after waiting for
the entire `make` command to run. The default prefix is always
`/usr/local` which requires root privileges to install into. However,
there is apparently the [env variable `DESTDIR`][1] which will at
least allow you to add a prefix in front of the default prefix. It
won't "change" it, so you're always stuck with `/usr/local` unless you
actually set the `--prefix` flag before building. But this does let
you do `asdf/usr/local`.
```sh
make DESTDIR=$HOME install
```
```sh
cmake DESTDIR=$HOME --install ./
```
2021-08-29 15:58:57 -07:00
# Copyright
2021-11-23 00:30:24 -08:00
I think this script is too small to reasonably apply copyright to. It
is in the Public Domain. You may use it for any purpose without
restrictions.
2021-09-07 22:19:42 -07:00
[1]: https://cmake.org/cmake/help/latest/envvar/DESTDIR.html#envvar:DESTDIR