Permission Denied while trying to install ruby gems on ubuntu 16.04 - ruby-on-rails

I am trying to install ruby gems on my computer running Ubuntu 16.04. I use bash with the oh-my-zsh framework.
When I run the command:
curl -L https://get.rvm.io | bash -s stable --ruby
I get the error message:
mktemp: failed to create file via template '/usr/share/rvm/rvm-exec-test.XXXXXX': Permission denied
How do I set up the permissions for this to work properly?

You can use:
curl -L https://get.rvm.io | sudo bash -s stable --ruby
NOTE: Running a script as sudo can be very dangerous if you don't know what it is actually doing. Make sure to check the script and if possible give the appropriate permissions to the required files and or folders it needs to access. For some more info regarding why it can be dangerous see https://elementaryos.stackexchange.com/questions/448/why-is-running-commands-with-sudo-dangerous
Quick example with your particular use case, as can be seen in the link:
"...If a website is asking you to curl http://link/to/script | sudo bash, don't do that. Download the script, take a quick look, and after that, you can run it. Even if the original author did not intend to make the script malicious, someone might have compromised the original author's accounts and uploaded a new, "updated" script. You are the one responsible for your computer's integrity, and therefore you need to be familiar with your system's capabilities."

Make The directory as read and write ... cd dirname chmod 777
or
sudo gem install 'gem name','version'

Related

Could not login with bash shell by default

I want to run a Ruby on Rails application. When I tried to run it, it shows me this,
The program 'rails' is currently not installed. You can install it by typing:
sudo apt install ruby-railties
So, I figured out the problem and I found that the problem is due to not login into bash shell. My terminal could not execute 'ruby' or 'ruby on rails' scripts. I checked .bashrc and .bash_profile files if PATH variable is set to point to rvm file.
When I did,
/bash/bin -l
it shows me ruby or rails are installed on system and I could start Rails server successfully. But if I opened another Terminal window, same problem occurs. Basically, I want to log into bash shell by default. Please correct and help me to sort out this. Thanks!
If you are sure the location of your bash shell is /bin/bash you could use this command (replacing "username" with your username):
chsh -s /bin/bash username
That will change your default shell in most unix like operating systems.
Afterwards you can verify it checking /etc/passwd where you will see the default shell at the end of the line of your username.
Warning: Try it first with a new user, in order to avoid losing your shell access if the path to bash is different :-)

System user in Ubuntu server does not search right TexLive path

Short question: my system user (name sharelatex) does not search in manually installed TexLive in /usr/local/texlive but search in /usr/share/texlive (I don't know why there is this folder here, I didn't install TexLive from Ubuntu repo). My another normal user and root user can search well in /usr/local/texlive. How can I force sharelatex user to search in /usr/local/texlive? Thanks!
Detail: I'm trying to install sharelatex onto my Ubuntu server.
I have manually installed TexLive using:
wget http://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz
tar -xvf install-tl-unx.tar.gz
cd install-tl-*
sudo ./install-tl
While installing, I have created a system user named sharelatex and added it to group sharelatex by these 2 commands:
sudo adduser --system --home /var/www/sharelatex --no-create-home --group sharelatex
sudo chown -R sharelatex:sharelatex /var/www/sharelatex
When I login as root or normal user, the output of the command
which latex
is
/usr/local/texlive/2015/bin/x86_64-linux/latex
However,when I try to run the same command as sharelatex user:
sudo -u sharelatex which latex
the output is
/usr/bin/latex
I also think this was the problem about $PATH with system user sharelatex. Even I have tried to put my TexLive directory to /etc/environment, my sharelatex user still cannot find it. However, after take a closer look at sharelatex service files, I see that the path for sharelatex seems to be set again when sharelatex execute latex command. Here is how to fix it:
Step 1. Search for your upstart files sharelatex-SERVICE.conf where SERVICE should be replaced with web, chat,clsi,... Full list as below:
sharelatex-chat.conf
sharelatex-clsi.conf
sharelatex-docstore.conf
sharelatex-document-updater.conf
sharelatex-filestore.conf
sharelatex-real-time.conf
sharelatex-spelling.conf
sharelatex-tags.conf
sharelatex-template.conf
sharelatex-track-changes.conf
sharelatex-web.conf
If you follow the installation manual from sharelatex github, these files are probably in /etc/init.
Step 2. In each file, you will see this line:
LATEX_PATH=/usr/local/texlive/2015/bin/x86_64-linux
This line will set LATEX_PATH variable to the right TexLive. And in the ending of the file, you will see the line that will execute TexLive command:
exec sudo -u $USER -g $GROUP env SHARELATEX_CONFIG=$SHARELATEX_CONFIG NODE_ENV=production PATH=$PATH:$LATEX_PATH $NODE app.js >> /var/log/sharelatex/$SERVICE.log 2>&1
What you need to do it to swap $PATH:$LATEX_PATH to become PATH=$LATEX_PATH:$PATH. By doing this, the directory to the right TexLive will be search first.
Make this change to all the sharelatex-SERVICE.conf listed above.
After editing all those files, you might want to restart all those services (search for restart upstart services), or maybe just restart the machine.

Installed GNU grep on OSX, but can't use

I've tried installing GNU grep on OSX, and it seems to be installed, but I can't use it.. I've done so using homebrew, Macports is having some issues currently, so I can't use that.
To install: brew tap homebrew/dupes; brew install grep
Which returns: Warning: homebrew/dupes already tapped! Warning: homebrew/dupes/grep-2.21 already installed
Symlinking seems to work to /usr/local/bin/ggrep. When I add the alias alias grep="ggrep" and do grep --version, I get -bash: ggrep: command not found. Which is true, since there is no ggrep in the folder. I've tried installing with and without --with-default-names.
The folder /usr/local/Cellar/grep/2.21/bin/ contains the following:
-r-xr-xr-x 1 Wes admin 158 Oct 14 09:27 egrep
-r-xr-xr-x 1 Wes admin 158 Oct 14 09:27 fgrep
Which is strange to me, since the documentation implies that The command has been installed with the prefix "g".
I've seen the following post, but none of the solutions work for me. Updating grep for Mac OS 10.7
Does anyone have any solutions? I really want to use GNU grep.
Output of brew unlink grep && brew link grep -v:
Unlinking /usr/local/Cellar/grep/2.21...
6 symlinks removed
Linking /usr/local/Cellar/grep/2.21...
ln -s ../Cellar/grep/2.21/bin/egrep egrep
ln -s ../Cellar/grep/2.21/bin/fgrep fgrep
ln -s ../../Cellar/grep/2.21/share/info/grep.info grep.info info /usr/local/share/info/grep.info
ln -s ../../../Cellar/grep/2.21/share/man/man1/egrep.1 egrep.1
ln -s ../../../Cellar/grep/2.21/share/man/man1/fgrep.1 fgrep.1
ln -s ../../../Cellar/grep/2.21/share/man/man1/grep.1 grep.1
6 symlinks created`
New:
brew uninstall grep; brew install grep
$ which -a grep
/usr/bin/grep
$ which -a ggrep
/usr/local/bin/ggrep
$ echo $PATH
/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin
This time, it seems something is different. ggrep is finally installed! I think the unlink/link straightened some things out.
How can I set ggrep as the default? With alias?
To make GNU grep the default install it with --with-default-names:
$ brew install grep --with-default-names
If you already have it installed use reinstall instead of install.
Ensure that /usr/local/bin (the location of GNU grep) is before /usr/bin (the location of the BSD grep) in your $PATH; which seems to be the case here.
You might have to start a new shell session afterward because Bash caches the binaries paths for the current session. This means that the first time you use grep it’ll determine which binary it’ll use depending on your $PATH and cache it. The next time it’ll use the cached value so changing your $PATH won’t change anything until you reload the shell.
Offically out of date for the answer above.
As of Homebrew version 2.0.0 the --with-default-names flag is no longer available.
from the official documentation
--with-default-names is no longer supported. It is now installed into its own directory and you will need to adjust your PATH to use it.
What you need to do is to add this command to your shell
PATH="/usr/local/opt/grep/libexec/gnubin:$PATH"
As of Febuary 8, 2020, You could either prepend the PATH and MANPATH variables as eleijonmarck proposes, or use symbolic links to a path loaded early on the PATH. If you choose to use eleijonmarck's method, I would do it differently.
You need to know where Homebrew installs grep binaries.
PATH=/usr/local/opt/grep/bin:$PATH
as opposed to libexec. The Filesystem Hierarchy specifies that the libexec directory
includes internal binaries that are not intended to be executed directly by users or shell scripts.
Also, if you are doing that, then you might want the MAN pages too.
MANPATH=/usr/local/opt/grep/share/man:$MANPATH
The other option is to use symbolic links. You might think to do this:
ln -s /usr/local/opt/grep/bin/grep /usr/local/bin/
The thing is, this won't work, because MacOS has grep as a built-in. Instead, would need to remove or replace the built-in at /usr/bin. You could rename it mv /usr/bin/grep /usr/bin/bsdgrep. This effectively makes grep not findable at /usr/bin, but still usable as bsdgrep (advantage of this technique). Assuming you added grep to /usr/local/bin, you could test your change with:
which grep && grep -V # prove old grep found first
which grep && grep -V # prove new grep found first
The disadvantage of this technique is that you must add a symbolic link per binary.

Unable to run ruby script over ssh into ec2 instance

I'm working with ec2 instances and was trying to execute a ruby script on another instance after ssh to that instance.
I have a ruby script which updates configuration files, so i need to run that script as super user. when i run the script manually on that instance, sudo ruby recreate-532d01c.rb, the error that comes is
sudo: ruby: command not found
Running simple scripts with no root permissions works, eg.ruby file_1.rb.
Using rvmsudo in place of sudo executes the script with warning,
ubuntu#ip-10-0-0-111:~$ rvmsudo ruby recreate-82bb000012.rb
Warning: can not check `/etc/sudoers` for `secure_path`, falling back to call via `/usr/bin/env`, this breaks rules from `/etc/sudoers`. Run:
export rvmsudo_secure_path=1
to avoid the warning, put it in shell initialization file to make it persistent.
In case there is no `secure_path` in `/etc/sudoers`. Run:
export rvmsudo_secure_path=0
to avoid the warning, put it in shell initialization file to make it persistent.
I tried to execute the below command from rails console of one of the instance to test and it fails to recognize ruby as command
1.9.3-p545 :002 > system("ssh -i /home/ubuntu/.ssh/own_key.pem ubuntu#**.***.***.** ruby execute-52d.rb")
bash: ruby: command not found
I tried with possible solutions over web, but could not resolve the issue. I have the same configuration running for one of my old aws acount, this is a newly created account. Not sure if this could be issue in any way as currently ec2 instances fall under vpc by default and have some changes after dec 2013
Nothing to do with your VPC. So when you run your ruby script with sudo your environment that your user is using doesn't get set for Ruby.
Sounds like you may be using rvm and you probably set it up with a 'single user' config.
Try running as your user:
which ruby
and see where your ruby executable is located at. That's what you have to make sure that when your run your script as sudo it's available in the PATH.
Worst case you would have to reinstall rvm with multiuser config which should work when you run with sudo:
user$ \curl -sSL https://get.rvm.io | sudo bash -s stable

Permission denied when trying to install RVM?

I renamed my Macbook home directory to "hmumin" from "macbookpro".
I then tried to install RVM using:
$ curl -L https://get.rvm.io | bash -s
but I get an error:
mkdir: /Users/macbookpro/.rvm/src: Permission denied
Is this error from trying to install RVM in the previous home directory?
If I run:
open /Users/macbookpro
I get:
The file /Users/macbookpro does not exist.
Yet, if I run:
mkdir /Users/macbookpro
I get:
mkdir: /Users/macbookpro: Permission denied
It's pretty confusing, I just want to install RVM.
When I type RVM I also get this type of error:
cat: /Users/macbookpro/.rvm/VERSION: No such file or directory
Warning! PATH is not properly set up, '/Users/macbookpro/.rvm/gems/ruby-2.0.0- p353#railstutorial_rails_4_0/bin' is not at first place,
usually this is caused by shell initialization files - check them for 'PATH=...' entries,
it might also help to re-add RVM to your dotfiles: 'rvm get stable --auto-dotfiles',
to fix temporarily in this shell session run: 'rvm use ruby-2.0.0-
p353#railstutorial_rails_4_0'.
-bash: /Users/macbookpro/.rvm/scripts/base: No such file or directory
-bash: /Users/macbookpro/.rvm/scripts/help: No such file or directory
hmumin:~ hmumin$
It sounds like you have multiple problems, and they need to be addressed individually before you can successfully install RVM:
You can't rename your home directory and expect a machine to be happy. There are multiple places that track your home directory name, including the security system that maintains the user and group information. You need to check on "Ask Different" for how to correctly recover from this situation, and then how to correctly change your home directory as it is off-topic for Stack Exchange.
Carefully read the instructions for RVM installation at http://rvm.io/rvm/install. RVM is a very easy-to-install Ruby manager, however there are decisions you have to make up front, before you begin installing it. I'd strongly recommend you do the single-user installation, but, no matter which you choose, read the entire page first.

Resources