How to install a command once for all login users in Linux All In One

发布时间 2023-09-23 12:00:46作者: xgqfrms

How to install a command once for all login users in Linux All In One

/etc/profile & /etc/profile.d/

NVM

home/eric/.nvm/nvm.sh

$ ssh eric@rpi4b.local
# eric
$ sudo vim /etc/profile

$ cat /etc/profile
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

if [ "$(id -u)" -eq 0 ]; then
  PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
else
  PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games"
fi
# export PATH

# nvm 安装的node.js 复用测试✅
# PATH=$PATH:/home/eric/.nvm/versions/node/v18.18.0/bin
# nvm 查找路径, 权限问题 ❌
PATH=$PATH:/home/eric/.nvm

export PATH


if [ "${PS1-}" ]; then
  if [ "${BASH-}" ] && [ "$BASH" != "/bin/sh" ]; then
    # The file bash.bashrc already sets the default PS1.
    # PS1='\h:\w\$ '
    if [ -f /etc/bash.bashrc ]; then
      . /etc/bash.bashrc
    fi
  else
    if [ "$(id -u)" -eq 0 ]; then
      PS1='# '
    else
      PS1='$ '
    fi
  fi
fi

if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r $i ]; then
      . $i
    fi
  done
  unset i
fi

# profile test ✅
/home/eric/Desktop/auto-install-profile.sh

image

$ ssh nas@rpi4b.local
nas@rpi4b.local's password: 
Permission denied, please try again.
nas@rpi4b.local's password: 
Linux rpi4b 6.1.21-v8+ #1642 SMP PREEMPT Mon Apr  3 17:24:16 BST 2023 aarch64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sat Sep 23 11:23:00 2023 from fe80::1cca:fd24:3443:cda0%wlan0
auto run install test ✅
/etc/profile.d/ ?
temp = 
nvm had  been installed ✅
finished ?
auto run install test ✅
/etc/profile ❓
nas@rpi4b:~ $ nvm -v
-bash: nvm: command not found
nas@rpi4b:~ $ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/home/eric/.nvm/versions/node/v18.18.0/bin
nas@rpi4b:~ $ node -v
v18.18.0
nas@rpi4b:~ $ node -v
v18.18.0
nas@rpi4b:~ $ exit
logout
Connection to rpi4b.local closed.

image

$ ssh nas@rpi4b.local
# nas
nas@rpi4b:~ $ node -v
-bash: node: command not found
nas@rpi4b:~ $ nvm --help
-bash: nvm: command not found
nas@rpi4b:~ $ nvm -v
-bash: nvm: command not found
nas@rpi4b:~ $ cat home/eric/.nvm/nvm.sh 
cat: home/eric/.nvm/nvm.sh: No such file or directory
nas@rpi4b:~ $ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/home/eric/.nvm
nas@rpi4b:~ $ ls /home/eric/.nvm
CODE_OF_CONDUCT.md  Makefile            bash_completion  rename_test.sh
CONTRIBUTING.md     PROJECT_CHARTER.md  install.sh       test
Dockerfile          README.md           nvm-exec         update_test_mocks.sh
GOVERNANCE.md       ROADMAP.md          nvm.sh           versions
LICENSE.md          alias               package.json
nas@rpi4b:~ $ /home/eric/.nvm/nvm.sh -h
-bash: /home/eric/.nvm/nvm.sh: Permission denied
nas@rpi4b:~ $ sudo /home/eric/.nvm/nvm.sh -h
[sudo] password for nas: 
Sorry, try again.
[sudo] password for nas: 
nas is not in the sudoers file.  This incident will be reported.
nas@rpi4b:~ $ 

is not in the sudoers file

image

demos

(? 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!

refs

https://stackoverflow.com/questions/77150541/how-to-install-fnm-fast-node-manager-then-node-npm-versions-for-all-users-o/77152043#comment136022272_77152043



©xgqfrms 2012-2021

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 ?️,侵权必究⚠️!