Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to install pup for all users (i.e. in /usr/local/bin/) on Linux #145

Open
sebma opened this issue Nov 1, 2020 · 13 comments
Open

How to install pup for all users (i.e. in /usr/local/bin/) on Linux #145

sebma opened this issue Nov 1, 2020 · 13 comments

Comments

@sebma
Copy link

sebma commented Nov 1, 2020

Hi,

Can you please update your README.md to explain how to install pup for all users (i.e. in /usr/local/bin/) ?

@gromgit
Copy link

gromgit commented Nov 3, 2020

There's been a one-line PR to fix just that (#116), in limbo for over 18 months now, so I wouldn't hold my breath if I were you.

@sebma
Copy link
Author

sebma commented Nov 3, 2020

@gromgit Thanks for the info.
Finally, I just copied the pup binary to /usr/local/bin/ because I noticed pup did not need other .so files than that of the system :

$ ldd $HOME/go/bin/pup | grep $HOME
$

@gromgit
Copy link

gromgit commented Nov 3, 2020

other .so files

Oh, sorry, I saw /usr/local/bin and assumed you were on macOS. You can actually just set the GOBIN environment variable to point to wherever you want Go-built binaries to be installed, e.g.:

GOBIN=/usr/local/bin go get github.com/ericchiang/pup

For more information on the (long) list of Go environment variables: go help environment.

@sebma
Copy link
Author

sebma commented Nov 3, 2020

other .so files

Oh, sorry, I saw /usr/local/bin and assumed you were on macOS. You can actually just set the GOBIN environment variable to point to wherever you want Go-built binaries to be installed, e.g.:

GOBIN=/usr/local/bin go get github.com/ericchiang/pup

For more information on the (long) list of Go environment variables: go help environment.

@gromgit Thanks a lot, just what I needed 👍
Yes, as you have rightly noticed, I'm using Linux :)
I use /usr/local/bin for standalone binaries that are not distributed by the OS.
Therefore, on Linux, sudo is needed because /usr/local/bin is not writable by non admin users by default :

$ sudo GOBIN=/usr/local/bin go get github.com/ericchiang/pup
$ # Or one can type
$ exort GOBIN=/usr/local/bin # One can move this GOBIN variable value assignment inside ".profile" file 
$ sudo -E go get github.com/ericchiang/pup # and just use the "sudo -E go get whatever/you/want"
$ alias goSudo='\sudo -E go' # Can be moved in a ".bash_aliases" file and then one can type "goSudo get github.com/ericchiang/pup"
$ which pup
/usr/local/bin/pup

God bless you.

@gromgit
Copy link

gromgit commented Nov 3, 2020

Therefore, on Linux, sudo is needed because /usr/local/bin is not writable by non admin users by default

It's not a good idea to run go as root, in the same way every project I've seen uses root only at the install phase, never the build portion.

Instead, consider making /usr/local/bin writable by a special admin group, then add yourself to that group. Look in /etc/group to see what's used on your system. For example, Ubuntu uses adm, so:

$ sudo usermod -a -G adm my_username
$ sudo chgrp adm /usr/local/bin
$ sudo chmod g+w /usr/local/bin
# Logout and login again, then this should work without any permission issues...
$ GOBIN=/usr/local/bin go get github.com/ericchiang/pup

@sebma
Copy link
Author

sebma commented Nov 3, 2020

@gromgit It's sad go doesn't have a download-only command, then I would do :

$ go download github.com/ericchiang/pup
$ sudo -E go install pup

However, I don't see want wrong downloading the package as root, doesn't sudo apt-get install already download packages as root also, before installing them ?

@gromgit
Copy link

gromgit commented Nov 3, 2020

go downloads arbitrary unauthenticated source code to compile and install, while apt-get install downloads and installs pre-compiled and signed binary packages that have been vetted by the repository maintainers. The two are worlds apart from a security standpoint.

Now, you could try to split the compile and install phases:

$ go build github.com/ericchiang/pup
$ sudo -E go install pup

but that may cause some files in your Go cache to be created as root (during go install), which may in turn cause permission issues in future go operations.

@sebma
Copy link
Author

sebma commented Nov 3, 2020

@gromgit You're absolutely right, apt packages are signed, I had forgotten about that, sorry 😄

I like your go build solution !
So I've just removed the ~/go/src/github.com/ericchiang/ directory and ran go build .... but it says :

$ go build github.com/ericchiang/pup
can't load package: package github.com/ericchiang/pup: cannot find package "github.com/ericchiang/pup" in any of:
	/usr/src/github.com/ericchiang/pup (from $GOROOT)
	/home/sebastien/go/src/github.com/ericchiang/pup (from $GOPATH)

@gromgit
Copy link

gromgit commented Nov 4, 2020

Since you blew away the cached source, you'd need to go get it again.

That's why I recommended adjusting the writability of /usr/local/bin instead: It results in the least number of gotchas and extra steps needed.

@sebma
Copy link
Author

sebma commented Nov 4, 2020

@gromgit OK, got it :)

@sebma
Copy link
Author

sebma commented Apr 23, 2021

@gromgit

Therefore, on Linux, sudo is needed because /usr/local/bin is not writable by non admin users by default

It's not a good idea to run go as root, in the same way every project I've seen uses root only at the install phase, never the build portion.

Instead, consider making /usr/local/bin writable by a special admin group, then add yourself to that group. Look in /etc/group to see what's used on your system. For example, Ubuntu uses adm, so:

$ sudo usermod -a -G adm $USER
$ sudo chgrp adm /usr/local/bin
$ sudo chmod g+w /usr/local/bin
# Logout and login again, then this should work without any permission issues...
$ GOBIN=/usr/local/bin go get github.com/ericchiang/pup

Hi Adrian,

The go binary on my Linux doesn't belong to the adm group but to the root group.

Your solution works like a charm but I wonder how come ?

BTW : Does go get have a verbose option, I tried go get -v but it didn't print any information ?

@sebma sebma changed the title How to install pup for all users (i.e. in /usr/local/bin/) How to install pup for all users (i.e. in /usr/local/bin/) for Linux Apr 23, 2021
@gromgit
Copy link

gromgit commented Apr 23, 2021

The go binary on my Linux doesn't belong to the adm group but to the root group.

The ownerships on a compiler binary (go in this case) do not affect the ownerships of its output (pup). What matters is who runs the compiler; running go as yourself generates binaries owned by you, while running sudo go produces root-owned binaries.

Your solution works like a charm but I wonder how come ?

The "secret sauce" involves:

  1. picking an appropriate group ownership for /usr/local/bin
  2. adding yourself to that group
  3. making /usr/local/bin owned and writable by that group

In the commands I presented earlier, usermod takes care of [2], while chgrp and chmod handle [3].

@sebma
Copy link
Author

sebma commented Apr 23, 2021

The go binary on my Linux doesn't belong to the adm group but to the root group.

The ownerships on a compiler binary (go in this case) do not affect the ownerships of its output (pup). What matters is who runs the compiler; running go as yourself generates binaries owned by you, while running sudo go produces root-owned binaries.

Your solution works like a charm but I wonder how come ?

The "secret sauce" involves:

1. picking an appropriate group ownership for `/usr/local/bin`

2. adding yourself to that group

3. making `/usr/local/bin` owned and writable by that group

In the commands I presented earlier, usermod takes care of [2], while chgrp and chmod handle [3].

@gromgit Thanks man !

How come I had forgotten that it is the user's group membership that runs the command that matters, given that the file/directory already has write access rights for that group :)

Cheers.

@sebma sebma changed the title How to install pup for all users (i.e. in /usr/local/bin/) for Linux How to install pup for all users (i.e. in /usr/local/bin/) on Linux Jul 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants