Gem not installing package - ruby

So I'm trying to install a package
$ sudo gem install compass
to be specific. It installs correctly and shows up when I do a list:
$ gem list
*** LOCAL GEMS ***
chunky_png (1.2.5)
compass (0.12.2)
fssm (0.2.9)
sass (3.1.20)
but for some reason when I try to run compass nothing happens. It says the command is not found. What am I doing wrong?
$ compass
bash: compass: command not found
I'm running Ubuntu if that helps.

Confirm that there is output for locate -r /compass.rb$, then echo $GEM_HOME. You should find that gem doesn't know about the directory that compass installed to. You can either move it from its previous location into the directory specified by GEM_HOME, or else append that directory to the variable in your ~/.bash_rc file. Much better, though, would be to use rvm for managing your gems (and Rubies), as it neatly avoids this sort of issue and also allows much finer control over the whole process.

This problem can be solved by follwing this:
http://markushedlund.com/dev-tech/ubuntu-compass-command-not-found
The problem is concerned about the global variable PATH that is not being updated correctly when installing gem compass
Run
echo "PATH=\$PATH:/var/lib/gems/1.8/bin:\$HOME/.gem/ruby/1.8/bin" >>
/etc/profile.d/rubygems1.8.sh
and re-login

Related

Error installing SASS gem - don't have permissions

I'm not well versed in terminal, but I'll try my best to make this as clear and concise as I can.
I'm trying to install SASS and get the following errors:
When using gem install sass I get .
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory.
When using sudo gem install sass I get .
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/bin directory.
I have Xcode installed and I have agreed to the terms.
I even tried updating my Ruby, but terminal tells me I already have the most updated version.
ruby 2.3.3p222 (2016-11-21 revision 56859) [universal.x86_64-darwin17]
The worst part of all of this is that when I navigate to my Ruby/Gems/2.3.0/gems directory, there is a sass-3.5.5 folder!!! (linked image to follow)
Ruby directory path to sass folder
I try running sass -v and get -bash: sass: command not found
I feel like I've tried everything that I can think of or find online. I'm at a loss and definitely need some help.
The issue can be fixed by installing RVM or Rbenv for managing ruby versions and gems.
Also, FilePermissionError can be fixed using the -n parameter
sudo gem install sass -n /usr/bin
I prefer not touching sudo command, so I managed to solve this issue by referring to SASS home page:
If you use Node.js, you can also install Sass using npm by running
npm install -g sass
If you find it helpful, kindly upvote or leave comment so that I know it can solve your issues too.
Or one could update the directory for where gems are installed.
Please see the origional answer here: https://stackoverflow.com/a/2619731/3302764
export GEM_HOME=~/.gem
export GEM_PATH=~/.gem

Can't install gem using Bundler's Rakefile install task when developing a custom gem

I'm developing a couple of private gems and I think I don't understand correctly the PATH/GEM_PATH and/or Bundler/RVM installation flow, would love if someone could chip in.
I have a repository with two gems (A & B for simplicity sake). I've developed the gems using the scaffolding + following the guidelines provided by this bundler tutorial.
Thanks to the Bundler project I have a few Rakefile tasks like rake build, rake install, rake install:local and rake release. Because of the private nature of these gems I can't release them to RubyGems (and we haven't looked into hosting our rubygems).
My machines are using RVM to manage ruby versions and Bundler version 1.15.1
What I want to do: Assuming a new machine/developer trying out the project, ideally we would cd into each of the subfolders (currently 2, gem A and gem B), run rake install and after that we should have the gems available system wide for the current user.
What is happening: The gems are built and work properly, but they are only available inside the subfolder of each gem i.e. gem A is only available inside the subfolder A and gem B is only available inside subfolder B.
What I've tried: So, after rake build/install/install:local a new .gem file is generated under pkg. I've tried to manually install the "compiled" file using gem install pkg/A.gem, gem install --local pkg/A.gem and gem install --local --user-install pkg/A.gem without success. (there are plenty of SO questions/answers about this)
I believe this has something to do with the PATH variables, but like I said before I don't fully understand the way they are managed. I get the following results from these commands:
# Our gem
> gem which A
/home/ubuntu/.rvm/gems/ruby-2.4.0/gems/A-0.1.8/lib/A.rb
# Pry, available globally
> gem which pry
/home/ubuntu/.rvm/gems/ruby-2.4.0/gems/pry-0.11.1/lib/pry.rb
I've been lost and frustrated for far too long now, any help is appreciated. Also open to hear suggestions of better private gem installation flows :)
Yes, it has something to do with your PATH variables. Your installation seems to be good.
I advise you to first affirm your gems installation path with:
echo $GEM_HOME
The double check your PATH to ensure its present and also confirm that the GEM home is also where the gem got installed into from the rake install
echo $PATH
If not, put it in your path and you should be fine with something like this:
echo PATH=$PATH:$GEM_HOME >> ~/.bashrc
source ~/.bashrc
Build your gem as per that guide you linked. You should end up with a gem file. Distribute this as you see fit (I use rsync/crontab to download newer gem versions but anything goes). User can install the gem as follows:
gem install --user-install /path/to/your/file.gem
This will install the gem in the user's ~/.gem/ruby/<version>/gems/<your-gem-name> directory.
Tried it with an empty gem (foodie, as in that example guide) and it works fine. But if you don't specify the --user-install parameter it will try to install in the system ruby dir (/usr/lib/ruby/gems...)

Trouble installing bropages on OSX

When I try to install bropages on Mavericks, I get:
$ gem install bropages
Building native extensions. This could take a while...
ERROR: Error installing bropages:
ERROR: Failed to build gem native extension.
No such file or directory # dir_chdir - /Users/christian/.gem/gems/unf_ext-0.0.6/ext/unf_ext
Gem files will remain installed in /Users/christian/.gem/gems/unf_ext-0.0.6 for inspection.
Results logged to /Users/christian/.gem/extensions/x86_64-darwin-13/2.2.0- static/unf_ext-0.0.6/gem_make.out
And then:
$ cat /Users/christian/.gem/extensions/x86_64-darwin-13/2.2.0-static/unf_ext-0.0.6/gem_make.out
No such file or directory # dir_chdir - /Users/christian/.gem/gems/unf_ext-0.0.6/ext/unf_ext
I'm using ruby 2.2.1 and gem 2.4.5, both managed with rbenv. Any idea what could cause this?
Have you tried it with sudo, I am running into the same issues as you, but my errors mentioned permissions, so I am going to go with sudo. It is strange, as I had it installed once before, and now it no longer seems to be there.
Make sure you've installed the Xcode Command Line Tools, which brings with it a bunch of utilities, including what you need to build a gem module.
xcode-select --install
After you've installed the package, give the install another go.
I guess you are using a .gemrc in your home directory, where you specify the gemhome. Instead of using a ~ for your home directory you should enter the complete path. In your example it should look as follow:
$ cat ~/.gemrc
gemhome: /Users/christian/.gem/
There must be some inconsistency between the ruby/gem tools. If you use a ~ in .gemrc, a subdirectory called /current/working/directory/~/.gem is created, while the extensions are put into your homes /home/user/.gem/ directory.

Viewing a Gem's Source Code

Ruby dabbler/newbie here who's not familiar with the ecosystem, so apologies if this is one of those super duh questions.
Is there a way to view all the files and/or source code installed by a gem? That is, I just ran
$ gem install sass
And the sass gem is now a part of my local system
$ gem list --local
...
sass (3.1.16, 3.1.2)
...
I want to know what the gem install command put on my system. Is there a command I can run to see all the files installed by the gem?
After some googling, man gem and gem help commands, I discovered the contents command.
$ gem contents sass
However, when I run this command with the aforementioned sass gem, I get the following results
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/test/sass/engine_test.rb
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/test/sass/functions_test.rb
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/test/sass/extend_test.rb
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/test/sass/logger_test.rb
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/test/sass/css2sass_test.rb
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/test/sass/conversion_test.rb
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/test/sass/script_test.rb
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/test/sass/util/subset_map_test.rb
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/test/sass/util/multibyte_string_scanner_test.rb
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/test/sass/callbacks_test.rb
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/test/sass/importer_test.rb
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/test/sass/scss/css_test.rb
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/test/sass/scss/scss_test.rb
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/test/sass/scss/rx_test.rb
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/test/sass/util_test.rb
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/test/sass/script_conversion_test.rb
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/test/sass/less_conversion_test.rb
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/test/sass/cache_test.rb
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/test/sass/plugin_test.rb
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/bin/sass
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/bin/sass-convert
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.16/bin/scss
However, this list seems incomplete as I know there are files in
.../.rvm/gems/ruby-1.9.2-p180/gems/sass-3.1.2/lib/
Why does contents not show the files from lib?
Is it possible for a gem installer to install files outside of the gems folder?
Is there a command that can show everything installed by a gem?
gem has an unpack command: http://guides.rubygems.org/command-reference/#gem-unpack
gem unpack rake
ls rake-0.4.3/
There are two really good ways to do this. There is another gem which allows you to open the gem and edit. This gem is call gem-open
gem install gem-open
then
gem open sass
Another way is to generate your own rdocs.
gem rdoc sass
You can then look at your rdocs by
gem server
Also if you are using rvm, you can type rvm info and it will show GEM_HOME location.
This will be where all your gems source code is.
cd $GEM_HOME
cd gems/sass-3.1.2/
Update:
This is the way I mostly do this now, when using bundler.
cd $(bundle show sass)
This will be the version of sass in your Gemfile.
I usually open a gem by running this command from the console
EDITOR=<your editor> bundle open <name of gem>
The lib/ directory you mentioned is for version 3.1.2 of the gem; gem contents without --version will just list one version (it appears to pick the newest version, but I'm unable to verify this is always true). What output do you get for gem contents --version 3.1.2 sass?
You can also use just rename the .gem file to .tar and extract as a posix archive. The source code is inside it in the lib folder. See https://blog.srcclr.com/extracting-ruby-source-code-from-gem-packages/ for more details.
In addition to gem contents, another command you might find useful is gem environment. If you have multiple paths for your gem installations, they will all be listed under the "GEM PATHS" label.

How do I run a Ruby Gem?

This might seem stupid, but I recently tried to install SASS and followed their instructions:
$ gem install sass
$ sass --watch [...]
So I followed along:
root#server:~# gem install sass
Successfully installed sass-3.1.15
1 gem installed
Installing ri documentation for sass-3.1.15...
Installing RDoc documentation for sass-3.1.15...
root#server:~# sass
bash: sass: command not found
Despite looking around like an idiot trying to find some simple way to run something like gem run sass or some other workaround to make it function, I am more or less at a loss.
It seems that Debian/Ubuntu drops ruby gems into /var/lib/gems/1.8/bin.
So the solution (at least for Ubuntu/Debian) is:
$ sudo -s
# echo 'PATH=/var/lib/gems/1.8/bin:$PATH' > /etc/profile.d/gemspath.sh
# chmod 0755 /etc/profile.d/gemspath.sh
...and then open a new shell session.
(This is fixed in Ubuntu 11.10.)
If you happen to have installed Ruby through rbenv, you'll need to execute the following command
rbenv rehash
On macOS I had to add the gem executable directory to the path.
Add these lines to your ~/.bashrc file, and reopen the terminal to refresh the env vars.
# gem
gembin=`(gem env | sed -n "s/.*EXECUTABLE DIRECTORY: \(.*\)/\1/p")`
export PATH=$gembin:$PATH
If you use macOS and you:
I don't know/care about Ruby.
I just want to run this program.
Why is this so complicated?
Then run:
~/.gem/ruby/*/bin/jekyll
where jekyll is the thing you just installed with gem install.
If you're trying to run a simple WEBrick server for your gem you can do the following after installation:
sass start

Resources