Linux install for all users

How to install a module for all users with pip on linux?

How to install a package in the standard python environment i.e. /usr/local/lib/python2.7/dist-packages using pip and make this new package available for all the users without using virtualenv ? By using the following, the package is installed with root permissions only:

$ sudo pip install loremipsum Downloading/unpacking loremipsum Downloading loremipsum-1.0.5.tar.gz Running setup.py (path:/tmp/pip_build_root/loremipsum/setup.py) egg_info for package loremipsum Installing collected packages: loremipsum Running setup.py install for loremipsum Successfully installed loremipsum Cleaning up. 
$ python -c 'import loremipsum' Traceback (most recent call last): File "", line 1, in ImportError: No module named loremipsum $ sudo python -c 'import loremipsum' $ pip install loremipsum Requirement already satisfied (use --upgrade to upgrade): loremipsum in /usr/local/lib/python2.7/dist-packages Cleaning up. $ cowsay sad _____ < sad >----- \ ^__^ \ (oo)\_______ (__)\ )\/\ ||----w | || || 

Please do not advise me to use apt-get install python-. instead. I would like to know what is my mistake and how to use pip correctly.

$ python --version Python 2.7.6 $ pip --version pip 1.5.4 from /usr/lib/python2.7/dist-packages (python 2.7) $ uname -a Linux _ 3.19.0-32-generic #37~14.04.1-Ubuntu SMP _ x86_64 GNU/Linux 

EDIT I guess the problem is because pip does not allow the group and everyone to read the installed stuff:

$ sudo pip uninstall loremipsum Uninstalling loremipsum: /usr/local/lib/python2.7/dist-packages/loremipsum-1.0.5.egg-info /usr/local/lib/python2.7/dist-packages/loremipsum/__init__.py /usr/local/lib/python2.7/dist-packages/loremipsum/__init__.pyc /usr/local/lib/python2.7/dist-packages/loremipsum/default/dictionary.txt /usr/local/lib/python2.7/dist-packages/loremipsum/default/sample.txt /usr/local/lib/python2.7/dist-packages/loremipsum/generator.py /usr/local/lib/python2.7/dist-packages/loremipsum/generator.pyc Proceed (y/n)? y Successfully uninstalled loremipsum $ sudo pip install loremipsum Downloading/unpacking loremipsum Downloading loremipsum-1.0.5.tar.gz Running setup.py (path:/tmp/pip_build_root/loremipsum/setup.py) egg_info for package loremipsum Installing collected packages: loremipsum Running setup.py install for loremipsum Successfully installed loremipsum Cleaning up. $ sudo ls -al /usr/local/lib/python2.7/dist-packages/loremipsum total 60 drwxr-s--- 3 root staff 4096 Apr 27 22:06 . drwxrwsr-x 18 root staff 4096 Apr 27 22:06 .. drwxr-s--- 2 root staff 4096 Apr 27 22:06 default -rw-r----- 1 root staff 16182 Apr 27 22:06 generator.py -rw-r----- 1 root staff 16323 Apr 27 22:06 generator.pyc -rw-r----- 1 root staff 6130 Apr 27 22:06 __init__.py -rw-r----- 1 root staff 6869 Apr 27 22:06 __init__.pyc 

Источник

How to install Python Package for global use by all users (incl. www-data)

I thought I throw together a little dirty script on our server (Ubuntu 16.04) that gives me some plain text output from Python. I want to call the script like this from PHP (I know there should be some escaping done, but it’s just a test currently):

#!/usr/bin/python import CoolProp.CoolProp as CP import argparse print('Hallo Welt') 
  1. So I tried installing it with pip install CoolProp => That works for my local user. But now when called from user www-data
  2. After I tried to install it with a target —target=/usr/local/lib/site-packages/ but that did not help.
  3. I tried to change the ACL on the complete site-packages/ to rwx for www-data but that does not work as well.
Читайте также:  Linux increase partition size

In the end: What is the simplest way to pip install a package that can be used by all users including www-data ?

To add on this: Today I would do it completely different: 1) I would not call a python script from PHP but rather create a small python app (e.g. with flask) and deploy it as a wsgi app 2) The latter approach perfectly supports pipenv / virtual environments that bring their own package environment.

2 Answers 2

I recommend that you try the solution that xotihcan posted first as that is the easy way to make most python modules available to all users including www-data. However it doesn’t work for every python module. If that doesn’t work for you or you just want to install modules for the www-data user only then use the following commands:

sudo mkdir /var/www/.local sudo mkdir /var/www/.cache sudo chown www-data.www-data /var/www/.local sudo chown www-data.www-data /var/www/.cache sudo -H -u www-data pip install CoolProp 

I had this same issue trying to make the Python pyro4 module available for the www-data use. There is another way to do it but it involves some even dirtier hackery. For more details check out my question/answer @ How do I properly call a Python Pyro client using PHP and Apache web server?

Источник

How to install softwares for all users?

I am running an Ubuntu 18.04 server among a small group. How can I install some common software that all users can use at the same time? On my own laptop, I can just use apt-get . However, it has a huge limitation. For some package, it requires sudo to fully function. For example, when tmux is installed by apt-get , it requires sudo to properly load .tmux.conf . Without sudo , tmux starup takes forever. what is the best practice here?

apt-get install should always be prefaced by sudo , failure to do so will result in potentially incomplete installations. Whenever software is installed with apt tools, it should be installed for all users by default. Instead of using the old apt get commands, just do it directly with apt (apt install instead of apt-get install), if the system is configured properly it should automatically call it as root (sudo) and prompt for the password.

2 Answers 2

If you install software in Ubuntu using apt-get, it is installed system-wide for every user. However in nearly all cases, it is required to be root to do so. One way to become root -if you are not yet- is to prepend commands with sudo. This applies to all packages to be installed using apt-get.

Читайте также:  Kali linux on nexus

The problem, that you require root to start tmux is probably a different problem, unrelated to the package installation via apt-get. Maybe this could help you: https://serverfault.com/questions/405391/tmux-wont-run-as-non-root-user

You may want to look at how linux’s directory structure is constructed . For example, this link

Non-essential binaries for multi-user use can typically be placed in /usr, /usr/bin, or /usr/local/bin. This link here https://unix.stackexchange.com/questions/8656/usr-bin-vs-usr-local-bin-on-linux goes into greater detail.

Obviously package managers may put their apps elsewhere, but that is the historical purpose for these directories.

You must log in to answer this question.

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.17.43535

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

    Installed nvm in /opt/nvm as root. Seemed like an appropriate location.

# git clone git@github.com:creationix/nvm.git /opt/nvm 
export NVM_DIR=/usr/local/nvm source /opt/nvm/nvm.sh export NPM_CONFIG_PREFIX=/usr/local/node export PATH="/usr/local/node/bin:$PATH" 
# nvm install 0.10 # nvm alias default 0.10 

The node binaries should now be in the PATH for all users the next time you login to a shell session. NPM will install global things to the /usr/local/node prefix.

I tried following these instructions. When I ran nvm install node i get the following error nvm is not compatible with the «NPM_CONFIG_PREFIX» environment variable: currently set to «/usr/local/node»

nvm maintainer here. nvm is NOT COMPATIBLE with the «prefix» option, and you should NOT EVER install nvm as root. nvm is per-user. If you want to share node across users, nvm is the wrong tool to use.

I think comment from @LJHarb need more attention here. He is the maintainer of the nvm afterall. Maybe you should post that comment as answer?

Yes, it will be true forever. There’s no reason to use the «prefix» option at all anyways, and nvm can’t possibly ever be compatible with it.

It’s best to install one copy of node globally so that other users can access it. To do this, run the following command (entering your user’s password at the prompt):

n=$(which node);n=$; chmod -R 755 $n/bin/*; sudo cp -r $n/ /usr/local 

This commend is copying whatever version of node you have active via nvm into the /usr/local/ directory and setting the permissions so that all users can access them.

To check that it works, become the root user and do another which command to make sure that node is now installed to /usr/local/bin :

If you ever want to change the version of node that’s installed system wide, just do another nvm use vXX.XX.XX to switch your user’s node to the version you want, and then re-run the first command above to copy it to the system directory.

Читайте также:  Jetbrains rider linux key

This is most certainly not «best». It may be «convenient» but also the opposite of best if you need to run multiple versions of node under different user accounts. Using nvm (never installed as root) is the only easily applied option there.

I’m getting an cp: cannot stat ‘/‘: No such file or directory error here, on ubuntu debian. Any ideas for me?

  1. Login as root: sudo -s
  2. Install nvm: curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh | NVM_DIR=/usr/local/nvm bash
  3. Created a file called nvm.sh in /etc/profile.d with the following contents: #!/usr/bin/env bash export NVM_DIR=»/usr/local/nvm» [ -s «$NVM_DIR/nvm.sh» ] && \. «$NVM_DIR/nvm.sh» # This loads nvm
  4. Run /etc/profile.d/nvm.sh
  5. Install node: nvm install node
  6. Optionally update npm with: npm install -g npm

I had to create «/usr/local/nvm» first and also «chmod 755 /etc/profile.d/nvm.sh» «Run /etc/profile.d/nvm.sh» looks like «cd /etc/profile.d/nvm.sh» followed by «./nvm.sh» and also had to log out and back in for the nvm commands to work.

Install NVM on your Linux server, after that install node version using NVM (run all the command as root user). After that run the below command for all the users get nodejs available with nvm

n=$(which node);n=$; chmod -R 755 $n/bin/*; sudo cp -r $n/ /usr/local 

The above command is a bit complicated, but all it’s doing is copying whatever version of node you have active via nvm into the /usr/local/ directory (where user installed global files should live on a linux VPS/server) and setting the permissions so that all users can access them.

/root/.nvm/versions/node/v8.10.0/bin/node

Switch the user name check your node version.

su - username which node /usr/local/bin/node 

This command can break your sudo. Strongly reconsider using this as if you don’t have a root account you will be in for a world of pain

Since LJHarb recommends not installing this globally, I decided to create a script to install nvm when you login to the server. I needed this as I had several users setup that may login, but needed access to pm2 (to monitor one of our applications).

Create the script in /etc/profile.d/ (named nvm.sh for example):

#!/bin/bash NODE_VER=6.2.2 if [ ! -f ~/.nvm/nvm.sh ]; then # May need to be updated with the latest nvm release wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.32.0/install.sh | bash fi source ~/.nvm/nvm.sh if ! command -v node | grep -q $NODE_VER; then echo "Node is not installed" nvm install $NODE_VER nvm alias default $NODE_VER fi 

For our application, we needed pm2 shared between users:

if ! command -v pm2 &>/dev/null; then echo "pm2 not installed" npm install -g pm2 fi # Share pm2 configuration between users alias pm2='env HOME=/opt/sora pm2' 

Источник

Оцените статью
Adblock
detector