Why sudo when you can avoid sudo?

6 replies [Last post]
SuperTramp83

I am a translator!

Offline
Joined: 10/31/2014

There's a joke I made up while talking with a friend in Italian: it says "Ogni volta che uso sudo, sudo". Meaning "each time I use sudo, I sweat" :)

I have been using npm and pip for several months now to install a bunch of really cool applications, like say peerflix or mps-youtube.
When I learned how to use those I was instructed (most projects on github explicitly advise users to happily give sudo) to install applications using sudo. Now, we all know one should avoid giving superuser privileges lightly, and for obvious reasons.

Here is how you use npm without sudo ->

In terminal:
echo prefix=${HOME}/.local >> ~/.npmrc
which will create the file .npmrc in your /home with the liner prefix=/home/username/.local
And that's it. From then on npm will install everything in ~/.local/bin and ~/.local/lib

Here is how you use pip without sudo ->

Normally to install say youtube-dl via pip you would need to do it with sudo, in order to write to /usr (sudo pip install youtube-dl)

You can avoid it by simply appending the argument --user:
pip install --user youtube-dl

All executables will be placed ~/.local/bin/ and the python libraries in ~/.local/lib/

Finally, in order to make it comfortable for you (so you can type youtube-dl in the terminal and not the full path of the executable in ~/.local/bin/) to use those applications I recommend you add ~/.local/bin/ to your $PATH.

Sudo. With great power comes great responsibility. ^^

Majin Buu
Offline
Joined: 11/05/2016

Thanks for the info!! I'll use it...

SuperTramp83

I am a translator!

Offline
Joined: 10/31/2014

You are welcome. I'm glad this was helpful. :)

jbar
Offline
Joined: 01/22/2011

In the case of python we have virtual environments (python-virtualenv and python3-virtualenv). I use it only for pelican but I can say it's a great way to isolate different python or library versions.

http://docs.python-guide.org/en/latest/dev/virtualenvs/

SuperTramp83

I am a translator!

Offline
Joined: 10/31/2014

True, I've been looking at that too, tx for the reminder, jbar!

Jodiendo
Offline
Joined: 01/09/2013

Que mucho sudo cuand uso el judo!