How is this $PATH being set to ruby for new user? - ruby

I've been toying with chef, and may have installed ruby along the way. Now I would like to upgrade to ruby 2.0. Anyhow I'm curious what could have caused ruby to be added to the path of all new users? Note: there's no mention of ruby in the new user's .bashrc, .profile, or in the global /etc/environment:
ubuntu#ip-10-10-10-10:~$ sudo useradd -m testuser
ubuntu#ip-10-10-10-10:~$ sudo su - testuser
testuser#ip-10-10-10-10:~$ ls -la
total 20
drwxr-xr-x 2 testuser testuser 4096 Mar 23 02:54 .
drwxr-xr-x 5 root root 4096 Mar 23 02:54 ..
-rw-r--r-- 1 testuser testuser 220 Apr 9 2014 .bash_logout
-rw-r--r-- 1 testuser testuser 3637 Apr 9 2014 .bashrc
-rw-r--r-- 1 testuser testuser 675 Apr 9 2014 .profile
testuser#ip-10-10-10-10:~$ echo $PATH
/home/testuser/.gem/ruby/1.9.3/bin:/opt/rubies/1.9.3-p429/lib/ruby/gems/1.9.1/bin:/opt/rubies/1.9.3-p429/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
testuser#ip-10-10-10-10:~$ ruby --version
ruby 1.9.3p429 (2013-05-15 revision 40747) [x86_64-linux]
testuser#ip-10-10-10-10:~$ which ruby
/opt/rubies/1.9.3-p429/bin/ruby
testuser#ip-10-10-10-10:~$
I'm at a loss as to where to look to find and remove the references to ruby 1.9.3 being added apparently automatically.

I faced similar issue. Please try with this option dpkg --get-selections.
As you might be knowing everything is considered as gems. Hence try with this also if above does not work...
$ gem -h
or
$rvm list known
and then you can install only the required version using
rvm install ruby 2.0.0-p247
REFERNCE:- http://www.ruby-lang.org/en/downloads/

Turns out somewhere along the way, somehow, chruby got installed. The quick fix to resolve the user PATH not being overwritten was to disable the .sh chruby put in /etc/profile.d:
ubuntu#ip-10-10-10-10:/etc/profile.d$ ls -l
total 16
-rw-r--r-- 1 root root 663 Aug 19 2015 bash_completion.sh
-rw-r--r-- 1 root root 147 Mar 21 00:58 chruby.sh
-rw-r--r-- 1 root root 1559 Jul 29 2014 Z97-byobu.sh
-rwxr-xr-x 1 root root 2691 Nov 23 18:41 Z99-cloud-locale-test.sh
ubuntu#ip-10-10-10-10:/etc/profile.d$ sudo mv chruby.sh chruby.sh.disabled
ubuntu#ip-10-10-10-10:/etc/profile.d$ ls
bash_completion.sh chruby.sh.disabled Z97-byobu.sh Z99-cloud-locale-test.sh
ubuntu#ip-10-10-10-10:/etc/profile.d$ sudo su - testuser
testuser#ip-10-10-10-10:~$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
Better would be to uninstall chruby, but it's not obvious to me how to do that given I don't know / don't remember how it was installed.

Related

RHEL Environment Variable Path To Mongo Shell

I have installed mongodb in one of our environments & this has been done using MongoDb Operations Manager. Though i have my PATH variable set correctly i'm unable to connect mongo shell with my user account but able to connect as a sudo. could someone help me if i'm missing anything here.
Details:
[user01#west.company.com#rhel01 /]$ echo $PATH
> /var/lib/mongodb-mms-automation/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/nfs/home/user01/.local/bin:/nfs/home/user01/bin
[user01#west.company.com#rhel01 /]$ mongo
> -bash: mongo: command not found
[user01#west.company.com#rhel01 /]$ sudo -i
[sudo] password for user01#west.company.com:
[root#rhel01 ~]# echo $PATH
> /var/lib/mongodb-mms-automation/bin:/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
[root#rhel01 ~]# mongo
> MongoDB shell
> version: 3.2.10 connecting to: test
> MongoDB Enterprise MYMONGOREPLSET01:PRIMARY>
Which Mongo Output:
[user01#west.company.com#rhel01 /]$ which mongo
/usr/bin/which: no mongo in (/var/lib/mongodb-mms-automation/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/nfs/home/user01/.local/bin:/nfs/home/user01/bin)
[root#rhel01 ~]# which mongo
/var/lib/mongodb-mms-automation/bin/mongo
Observation:
i just noticed the bin location is set like this ...
[root#rhel01 mongodb-mms-automation]# pwd
/var/lib/mongodb-mms-automation
[root#rhel01 mongodb-mms-automation]# ls -la
total 32
drwxr-xr-x 3 mongod mongod 4096 Mar 30 13:58 .
drwxr-xr-x. 57 root root 4096 Apr 1 03:23 ..
lrwxrwxrwx 1 mongod mongod 67 Nov 4 13:45 bin -> /var/lib/mongodb-mms-automation/mongodb-linux-x86_64-3.2.10-ent/bin
-rw------- 1 mongod mongod 1024 Mar 27 15:07 keyfile
-rw------- 1 mongod mongod 10686 Mar 30 13:58 mms-cluster-config-backup.json
drwxr-x--- 4 mongod mongod 4096 Nov 4 13:45 mongodb-linux-x86_64-3.2.10-ent
Try this
sudo chmod -R 777 /var/lib/mongodb-mms-automation/mongodb-linux-x86_64-3.2.10-ent/bin/
add this to path /var/lib/mongodb-mms-automation/mongodb-linux-x86_64-3.2.10-ent/bin

How can I check the available shells in Mac OSX?

How can I check all the different shells that I can use in OSX Terminal application?
The default one is bash, and I know zsh because I tried and it worked. I wonder how can I check if there are any more than this two.
The easy way is go to /etc and check the shells file. The content is the list of shells available in Mac OSX.
The included by default are:
/bin/bash
/bin/csh
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh
Alternatively, you can check their binaries by going to /bin and recognising them visually. Naturally, you have to know them in order to recognise them.
In MacOS the following command will list the available shells on your system
$ ls -l /bin/*sh
-r-xr-xr-x 1 root wheel 618448 Nov 19 00:26 /bin/bash
-rwxr-xr-x 1 root wheel 380016 Feb 7 16:11 /bin/csh
-r-xr-xr-x 1 root wheel 1287040 Sep 21 00:35 /bin/ksh
-r-xr-xr-x 1 root wheel 618512 Nov 19 00:26 /bin/sh
-rwxr-xr-x 1 root wheel 380016 Feb 7 16:11 /bin/tcsh
-rwxr-xr-x 1 root wheel 610288 Sep 21 00:35 /bin/zsh

-bash: cd: app: No such file or directory

I simply changed the name in finder and now when I use a command in terminal, this is the error I keep receiving. I've tried to look at all the other cases of the same error but they all pertain to different solutions that don't work. The path is clearly correct because when I try to cd into the directory, I'm already in the directory it is contained in.
Johns-MacBook-Air:SongAnalysisSentiment johnanukem$ cd app
-bash: cd: app: No such file or directory
Johns-MacBook-Air:SongAnalysisSentiment johnanukem$ ls
README app sentiments.csv songdictionary.py
Johns-MacBook-Air:SongAnalysisSentiment johnanukem$ ls -lah
total 776
drwxr-xr-x 8 johnanukem staff 272B Nov 14 02:38 .
drwx------+ 39 johnanukem staff 1.3K Nov 14 02:38 ..
-rw-r--r--# 1 johnanukem staff 6.0K Nov 14 01:39 .DS_Store
drwxr-xr-x 16 johnanukem staff 544B Nov 14 02:43 .git
-rw-r--r-- 1 johnanukem staff 35B Nov 14 01:38 README
drwxr-xr-x 8 johnanukem staff 272B Nov 14 02:38 app
-rw-r--r-- 1 johnanukem staff 370K Nov 14 01:49 sentiments.csv
-rw-r--r-- 1 johnanukem staff 1.3K Nov 14 02:29 songdictionary.py
type cd ap and then [Press Tab] to autocomplete, may be there is some spaces after app
On MacOS with the default Bash
$ bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin17)
Copyright (C) 2007 Free Software Foundation, Inc.
cd app raises the error
-bash: cd: app: No such file or directory
due to a bug of the super old Bash version installed with MacOS.
The workaround is to prefix the directory with ./ in this way
cd ./app
and it will work.
The alternative is to install a modern and better Bash version using Homebrew.
brew install bash

Modifying /private/etc/paths did not change $PATH after a reboot

On a rMBP here. I'm not sure what the script is that is responsible for doing this. Basically I want to add the path to python utils to the $PATH...
For example, I brewed python brew python in order to get pip, then ran pip install flake8. Now
$ which flake8
flake8 not found
$ find / | grep flake8
...
......
/usr/local/share/python/flake8
$ ls -la /usr/local/share/python/
total 32
drwxr-xr-x 6 lust admin 204 Apr 2 18:15 .
drwxr-xr-x 15 lust admin 510 Apr 2 18:12 ..
lrwxr-xr-x 1 lust admin 45 Apr 2 18:13 Extras -> ../../Cellar/python/2.7.3/share/python/Extras
-rwxr-xr-x 1 lust admin 389 Apr 2 18:15 flake8
-rwxr-xr-x 1 lust admin 385 Apr 2 18:15 pep8
-rwxr-xr-x 1 lust admin 405 Apr 2 18:15 pyflakes
Alright!
$ cat /private/etc/paths
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin
$ sudo vim /private/etc/paths
$ cat /private/etc/paths
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin
/usr/local/share/python
Make a new shell, check $PATH, python not there. Okay.
Reboot, start a new shell, check $PATH, python still not there.
Oh, by the way, the solution is not to append, with anything like export PATH=$PATH:newpath, because I don't actually care to run flake8 from the command-line, I want Sublime Text 3' SublimeLinter plugin to actually know where it is without putting some hacky config in the settings for the editor.
I found the problem. As part of oh-my-zsh, zsh is set up to set PATH in the ~/.zshrc. I failed to consider this. When starting ST3 without using the command line invocation, it gains its own (incorrect) path environment variable, so that part still doesn't work. The ultimate resolution to the problem, however, is here.

rvm system install, bins not properly symlinked

I'm on ubuntu 12.04 and installed rvm system wide with:
$ \curl -L https://get.rvm.io | sudo bash -s stable
So far I've always performed single user installs and to he honest I'm quite confused by the results of the system wide install.
It did put the rvm bin directory in my path, but it symlinked all the binaries with names that can't be directly used.
Does it mean that I should symlink them one by one?
Did something go wrong?
Is that the defalt behaviour?
appusr#server-name:/usr/local/rvm/bin$ ll
total 60
drwxrwsr-x 2 root rvm 4096 Apr 5 13:11 ./
drwxrwsr-x 23 root rvm 4096 Apr 5 13:04 ../
-rwxrwxr-x 1 root rvm 578 Apr 5 13:04 bundle*
lrwxrwxrwx 1 appusr rvm 41 Apr 5 13:11 erb-ruby-2.0.0-p0 -> /usr/local/rvm/wrappers/ruby-2.0.0-p0/erb*
lrwxrwxrwx 1 appusr rvm 48 Apr 5 13:11 erb-ruby-2.0.0-p0#global -> /usr/local/rvm/wrappers/ruby-2.0.0-p0#global/erb*
lrwxrwxrwx 1 appusr rvm 41 Apr 5 13:11 gem-ruby-2.0.0-p0 -> /usr/local/rvm/wrappers/ruby-2.0.0-p0/gem*
lrwxrwxrwx 1 appusr rvm 48 Apr 5 13:11 gem-ruby-2.0.0-p0#global -> /usr/local/rvm/wrappers/ruby-2.0.0-p0#global/gem*
lrwxrwxrwx 1 appusr rvm 41 Apr 5 13:11 irb-ruby-2.0.0-p0 -> /usr/local/rvm/wrappers/ruby-2.0.0-p0/irb*
lrwxrwxrwx 1 appusr rvm 48 Apr 5 13:11 irb-ruby-2.0.0-p0#global -> /usr/local/rvm/wrappers/ruby-2.0.0-p0#global/irb*
-rwxrwxr-x 1 root rvm 556 Apr 5 13:04 rake*
lrwxrwxrwx 1 appusr rvm 42 Apr 5 13:11 rake-ruby-2.0.0-p0 -> /usr/local/rvm/wrappers/ruby-2.0.0-p0/rake*
lrwxrwxrwx 1 appusr rvm 49 Apr 5 13:11 rake-ruby-2.0.0-p0#global -> /usr/local/rvm/wrappers/ruby-2.0.0-p0#global/rake*
lrwxrwxrwx 1 appusr rvm 42 Apr 5 13:11 rdoc-ruby-2.0.0-p0 -> /usr/local/rvm/wrappers/ruby-2.0.0-p0/rdoc*
lrwxrwxrwx 1 appusr rvm 49 Apr 5 13:11 rdoc-ruby-2.0.0-p0#global -> /usr/local/rvm/wrappers/ruby-2.0.0-p0#global/rdoc*
lrwxrwxrwx 1 appusr rvm 40 Apr 5 13:11 ri-ruby-2.0.0-p0 -> /usr/local/rvm/wrappers/ruby-2.0.0-p0/ri*
lrwxrwxrwx 1 appusr rvm 47 Apr 5 13:11 ri-ruby-2.0.0-p0#global -> /usr/local/rvm/wrappers/ruby-2.0.0-p0#global/ri*
lrwxrwxrwx 1 appusr rvm 42 Apr 5 13:11 ruby-2.0.0-p0 -> /usr/local/rvm/wrappers/ruby-2.0.0-p0/ruby*
lrwxrwxrwx 1 appusr rvm 49 Apr 5 13:11 ruby-2.0.0-p0#global -> /usr/local/rvm/wrappers/ruby-2.0.0-p0#global/ruby*
-rwxrwxr-x 1 root rvm 1307 Apr 5 13:04 rvm*
-rwxrwxr-x 1 root rvm 1512 Apr 5 13:04 rvm-auto-ruby*
-rwxrwxr-x 1 root rvm 1803 Apr 5 13:04 rvm-exec*
-rwxrwxr-x 1 root rvm 13130 Apr 5 13:04 rvm-installer*
-rwxrwxr-x 1 root rvm 3850 Apr 5 13:04 rvm-prompt*
-rwxrwxr-x 1 root rvm 2263 Apr 5 13:04 rvm-shell*
-rwxrwxr-x 1 root rvm 648 Apr 5 13:04 rvm-smile*
-rwxrwxr-x 1 root rvm 2229 Apr 5 13:04 rvmsudo*
lrwxrwxrwx 1 appusr rvm 44 Apr 5 13:11 testrb-ruby-2.0.0-p0 -> /usr/local/rvm/wrappers/ruby-2.0.0-p0/testrb*
lrwxrwxrwx 1 appusr rvm 51 Apr 5 13:11 testrb-ruby-2.0.0-p0#global -> /usr/local/rvm/wrappers/ruby-2.0.0-p0#global/testrb*
appusr#server-name:/usr/local/rvm/bin$
appusr#server-name:/usr/local/rvm/bin$
appusr#server-name:/usr/local/rvm/bin$
appusr#server-name:/usr/local/rvm/bin$ which ruby
appusr#server-name:/usr/local/rvm/bin$ which irb
appusr#server-name:/usr/local/rvm/bin$ which gem
appusr#server-name:/usr/local/rvm/bin$ /usr/bin/env ruby -v
/usr/bin/env: ruby: No such file or directory
appusr#server-name:/usr/local/rvm/bin$ ruby -v
The program 'ruby' can be found in the following packages:
* ruby1.8
* ruby1.9.1
Ask your administrator to install one of them
appusr#server-name:/usr/local/rvm/bin$
you should check /usr/local/rvm/wrappers especially /usr/local/rvm/wrappers/default for binaries that can be used from PATH with no other settings in environment.
I believe I found what was wrong. Apparently rvm wasn't properly loaded as a function, that is
$ type rvm | head -n 1
didn't return "rvm is a function", but something like "rvm is hashed" (...?...).
It is also interesting that the problem wasn't limited to the system wide install. I imploded the system wide rvm install, removed the references in /etc, and installed it again without sudo... same problem.
I'd say it was my fault, and by "my" I mean that I wasn't aware of how bash handles some user switches. It may be useful to others as well, so I'll report what I did.
I had ssh'd into the server as a general user and then switched to the user who will run the rails stack: su appusr (using bash).
After that, I installed rvm using:
$ \curl -L https://get.rvm.io | bash -s stable
When I tried the system wide install I of course also added the user to the rvm group with:
$ sudo usermod -a -G rvm appusr
...and logged out and in again: exit, and again su appusr.
Now, it seems that by doing so bash was only sourcing ~/.bashrc, and not ~/.bash_profile where rvm had placed the statement to load rvm as a function:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
Still, the rvm binary was in my PATH, and I could issue the commands needed to install ruby.
So far, so good.
The problem was that after the installation it somehow failed to select the only ruby I had installed as the default interpreter, and so it didn't create the symlinks.
I noticed it because when I issued rvm list I was presented with:
rvm rubies
ruby-2.0.0-p0 [ x86_64 ]
# => - current
# =* - current && default
# * - default
... notice how it was NOT marked with =*.
I used the command rvm use ruby-2.0.0-p0 --default, and I was warned that rvm wasn't loaded as a function and that something could not work (can't rememeber the exact message).
That was a breakthrough, and as I sourced ~/.bash_profile I could successfully select that ruby and all the symlinks (ruby, irb, rake, etc) were immediately created.
That wasn't ideal, though.
The default setup of my $HOME folder has the usual three files: ~/.profile, ~/.bash_profile and ~/.bashrc (plus the ones for zsh).
~/.bash_profile was added by the rvm installation, and I'm having it source ~/.profile.
~/.profile, then, automatically sources ~/.bashrc if bash is being used.
As I said, however, by doing su appusr bash just sources ~/.bashrc, and so fails to parse the statement loading rvm as a function. Very annoying.
Telling ~/.bashrc to source ~/.bash_profile would need some sort of control (an ENV variable?) to avoid an infinite reference loop, and seemed overkilling...
So I just moved [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" into ~/.bashrc, and I'd say everything seems to work now.

Resources