taking some "vacation" time to mess around and do some research on servery stuff primarily i'm interested in making shared space where we can all use shared rubies, gems, scripts, etc without requiring sudo privileges. i'm guessing this is what groups and proper permissions could be used for.
i followed this tutorial to create a directory for scripts in /opt
https://www.tecmint.com/create-a-shared-directory-in-linux/
grant@the-main-one:/$ cd opt/
grant@the-main-one:/opt$ ls
grant@the-main-one:/opt$ groups
grant sudo
grant@the-main-one:/opt$ mkdir scripts
mkdir: cannot create directory ‘scripts’: Permission denied
grant@the-main-one:/opt$ sudo mkdir scripts
[sudo] password for grant:
grant@the-main-one:/opt$ sudo groupadd scripters
grant@the-main-one:/opt$ sudo usermod --append --groups scripters grant
grant@the-main-one:/opt$ sudo chgrp -R scripters scripts/
grant@the-main-one:/opt$ sudo chmod -R 2775 scripts/
grant@the-main-one:/opt$ ls -lh
total 4.0K
drwxrwsr-x 2 root scripters 4.0K Aug 14 16:54 scripts
grant@the-main-one:/opt$ cd scripts/
grant@the-main-one:/opt/scripts$ nano become-scripter.sh
grant@the-main-one:/opt/scripts$ ls
grant@the-main-one:/opt/scripts$ groups
grant sudo
i found this list regarding where to put stuff on standard linux/unix systems
https://serverfault.com/questions/96416/should-i-install-linux-applications-in-var-or-opt
- /bin & /sbin are for vital programs for the OS, sbin being for administrators only
- /usr/bin & /usr/sbin are for not vital programs, sbin being for administrators only
- /var is for living data for programs. It can be cache data, spool data, temporary data (unless it's in /tmp, which is wiped at every reboot), etc.
- /usr/local is for locally installed programs. Typically, it hosts programs that follow the standards but were not packaged for the OS, but rather installed manually by the administrator (using for example ./configure && make && make install) as well as administrator scripts
- /opt is for programs that are not packaged and don't follow the standards. You'd just put all the libraries there together with the program. It's often a quick & dirty solution, but it can also be used for programs that are made by yourself and for which you wish to have a specific path. You can make your own path (e.g. /opt/yourcompany) within it, and in this case you are encouraged to register it as part of the standard paths
- /etc should not contain programs, but rather configurations.
i'm going to try and put asdf in a directory under /opt and see if its useful for all users
i started off doing this:
cd /opt
sudo mkdir asdfvm
sudo groupadd asdfvm
sudo usermod --append --groups asdfvm grant
sudo chgrp -R
but then realized maybe we'll want to do this with some other things in /opt so i wrote a script to make a new directory and group under opt. file:///opt/scripts/add-shared-opt-space
#!/usr/bin/sudo /bin/sh
usage() {
echo $(basename "$0"): ERROR: "$@" 1>&2
echo usage: $(basename "$0") 'directory [group]' 1>&2
exit 1
}
case $# in
0) usage "must provide at least one argument of directory name";;
1) directory="/opt/$1"; grp="$1";;
2) directory="/opt/$1"; grp="$2";;
*) usage "too many arguments";;
esac
# check if the directory already exists in opt and exit
if [ -d $directory ] ; then
echo $directory already exists.
exit
fi
echo "Making $directory with permissions for $grp group"
mkdir $directory
groupadd $grp
chgrp -R $grp $directory
chmod -R 2775 $directory
echo "Finished. Add relevant users to the group to use this space."
now with this shared space and proper permissions, i cloned asdf-vm into the directory in opt:
git clone https://github.com/asdf-vm/asdf.git /opt/asdfvm –branch v0.8.1
then, i added these lines to my .bashrc :
export ASDF_DIR=/opt/asdfvm
export ASDF_DATA_DIR=/opt/asdfvm
. /opt/asdfvm/asdf.sh
. /opt/asdfvm/completions/asdf.bash
they go in bashrc vs bashprofile because we want asdf commands to be available even in non-interactive shells, such as the things that run in the background for our editors/ides or whatever.
after this i was able to install the ruby plugin with asdf plugin add ruby
and
then successfully installed a Ruby with asdf install ruby latest
(i had to also
install a dependency sudo apt install zlib1g-dev
to build ruby)
after that its just a matter of setting the right .tool-versions
to use this
version:
grant@the-main-one:~$ ruby
No version set for command ruby
Consider adding one of the following versions in your config file at
ruby 3.0.2
grant@the-main-one:~$ touch .tool-versions
grant@the-main-one:~$ echo "ruby 3.0.2" >> .tool-versions
grant@the-main-one:~$ ruby -v
ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux]
grant@the-main-one:~$ which ruby
/opt/asdfvm/shims/ruby
grant@the-main-one:~$
now, all you need to do is add your user to the asdfvm
group and you can
use it to manage versions / libraries for many many languages and we all
share the benefits! (i hope)