What is gem install bundler? - ruby-on-rails

I know i can read it from http://bundler.io, but i have some doubts in my mind.
Is it like npm for NodeJs and Maven for Java/J2EE.
The first command i executed is gem install bundler. What is gem here and What is bundler, can some one enlighten me in terms of NodeJs or Maven.
Where these getting installed?. I don't specify -g like i do in
NodeJs for globally.
C:\Users\Shane>gem install bundler
Fetching: bundler-1.5.3.gem (100%)
Successfully installed bundler-1.5.3
Parsing documentation for bundler-1.5.3
Installing ri documentation for bundler-1.5.3
1 gem installed
C:\Users\Shane>gem install sqlite3
Fetching: sqlite3-1.3.9-x86-mingw32.gem (100%)
Successfully installed sqlite3-1.3.9-x86-mingw32
Parsing documentation for sqlite3-1.3.9-x86-mingw32
unable to convert "\x90" from ASCII-8BIT to UTF-8 for lib/sqlite3/1.8/sql
tive.so, skipping
unable to convert "\x90" from ASCII-8BIT to UTF-8 for lib/sqlite3/1.9/sql
tive.so, skipping
unable to convert "\x90" from ASCII-8BIT to UTF-8 for lib/sqlite3/2.0/sql
tive.so, skipping
Installing ri documentation for sqlite3-1.3.9-x86-mingw32
1 gem installed

I dont have much knowledge of nodejs or java but can give you some idea.
Is it like npm for NodeJs and Maven for Java/J2EE
Yes, It is somewhat like that npm.Bundler helps to manage application dependency like xyz app requires foo bar gem. gem is like of libraries which extend the app functionality. This gems are primary located in rubygems.org server.
The first command i executed is gem install bundler. What is gem here and What is bundler, can some one enlighten me in terms of NodeJs or Maven.
when you do gem install <gem_name> , it creates a request to rubygems.org and download the repo(gem) and put it in the configured location. The location can be found in gem env command. To get the details of gem, you have to use gem install <gem_name> -d . So, when you are doing gem install bundler, you are installing bundler gem. This gem will help you to resolve/manage/install application dependencies. This is like npm install bundler with npm .
Where these getting installed?. I don't specify -g like i do in NodeJs for globally.
No, there is no need to write -g option here. My default, we install gems in one location which is not inside apps. personally i think transferring all those gems from one computer to another is slightly cumbersome, rather i prefer to run a command which automatically install all dependency. This is where bundler shines. Let say you have an app which requires foo , bar dependency since it uses its functionality. Without bundler, you have install this gems by running gem install foo , gem install bar. But with bundler, you will just do bundle install and you are done.
That's all. This will give you good start.

gem install bundler installs a gem(library) that will help you to manage your project dependencies.
Then you have a project that contains a file called Gemfile , when you cd into that directory and enter bundle install it will install all gems needed for that project.
To check where your gems are being installed take a look at the output of gem env.

Related

Can't install ruby on rails in ubuntu gnome 15.10

I am trying to install ruby on rails. I'm at version 2.3.0 for ruby and gem version of 2.5.1.
When I run the command gem install rails I get an error that says:
ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /usr/local/lib/ruby/gems/2.3.0 directory.
How can I fix this?
gem install tries to put files in "system-wide" directories. These are protected, such that only the root user can write into.
You have at least three possibilities:
sudo gem install ..., this will write the gem files into /usr/local/lib/ruby/gems/2.3.0
gem install --user-install, this will install the gem "locally" in your users home directory
apt-get install ruby-rails (not sure about the package name), which will install the ruby on rails version maintained by your distributions maintainers (Canonical).
install and use rvm or rbenv (and there might be other options). Afterwards gem install will usually just work and install the gems for your user only
While the rvm setup might be a tiny bit confusing for newbies, I recommend using that approach. It will make updating and installing ruby, gems and different versions of it really easy.

How to install ruby on rails

I am newbie to ruby on rails, here i am trying to install ruby on rails on windows 7 64 bit. i installed the ruby installer and i installed rails. and also i created new app files. but when i start the rails server it is showing the following errors.
How can i get rid of these errors and start developing my ruby application?
C:\Users\walnut\Desktop > bundle install
Fetching gem metadata from https://rubygems.org/............
Fetching version metadata from https://rubygems.org/...
Fetching dependency metadata from https://rubygems.org/..
Resolving dependencies.................
Using rake 10.4.2
Using i18n 0.7.0
Installing json 1.8.3 with native extensions
Gem::InstallError: The 'json' native gem requires installed build tools.
Please update your PATH to include build tools or download the DevKit
from 'http://rubyinstaller.org/downloads' and follow the instructions
at 'http://github.com/oneclick/rubyinstaller/wiki/Development-Kit'
An error occurred while installing json (1.8.3), and Bundler cannot continue.
Make sure that `gem install json -v '1.8.3'` succeeds before bundling.
C:\Users\walnut\Desktop > rails s
Could not find gem 'mysql2 (>= 0) x64-mingw32' in any of the gem sources listed
in your Gemfile or available on this machine.
Run `bundle install` to install missing gems.
C:\Users\walnut\Desktop > gem install mysql2
Fetching: mysql2-0.3.19.gem (100%)
ERROR: Error installing mysql2:
The 'mysql2' native gem requires installed build tools.
Please update your PATH to include build tools or download the DevKit
from 'http://rubyinstaller.org/downloads' and follow the instructions
at 'http://github.com/oneclick/rubyinstaller/wiki/Development-Kit'
C:\Users\walnut\Desktop > rails s
Could not find gem 'mysql2 (>= 0) x64-mingw32' in any of the gem sources listed
in your Gemfile or available on this machine.
Run `bundle install` to install missing gems.
From here,
Follow the Instructions from the Ruby Installer Developer Kit Wiki:
Download DevKit file from rubyinstaller.org
Extract DevKit to path C:\RubyXXX\DevKit
Run cd C:\RubyXXX\DevKit
Run ruby dk.rb init
Run ruby dk.rb review
Run ruby dk.rb install
Where did you create your application? If you look at your command line, you are in your Desktop. You need to switch directories to your project folder to be in the right context.
Additionally, you need to install build tools to install json native extensions.
Please refer to/follow instructions from this other stack overflow answer - The 'json' native gem requires installed build tools.
As the error suggest you have to update your PATH to include build tools also known as DevKit.
If you have used RailsInstaller to install ruby on rails on your computer then it has already included in your rails installation directory. All you have to do now is to update your PATH to include it. See step 4 of instruction in DevKit Overview on Github.
If not follow above instruction to install DevKit and then get to work.
Try follow this step and one more thing, if you use x64 of ruby installer, then please use x64 devkit. Same applied to x86. I'm facing this issues and the link gave it(step to install) to you save my time. Hope this helped.
p/s : if i'm correct in windows, ruby v2.2 above was't support higher nokogiri, to get things working properly use either ruby v1.9.3 or v2.1.6.
Check this link also for nokogiri supported.

An error occurred while installing ruby-opencv (0.0.14)

I'm facing gem ruby-opencv installation issue
Gem files will remain installed in /home/k2/.rvm/gems/ruby-2.1.2#rails4/gems/ruby-opencv-0.0.14 for inspection.Results logged to /home/k2/.rvm/gems/ruby-2.1.2#rails4/extensions/x86_64-linux/2.1.0/ruby-opencv-0.0.14/gem_make.out
An error occurred while installing ruby-opencv (0.0.14), and Bundler cannot continue.
Make sure that `gem install ruby-opencv -v '0.0.14'` succeeds before bundling.
I tried below one also
gem install ruby-opencv -v '0.0.14'
ruby -v => 2.1.2
You need to download the opencv package from
https://github.com/Itseez/opencv/tree/master using,
git clone https://github.com/Itseez/opencv.git
or clicking on download button in that same page.
And install the above package using http://docs.opencv.org/doc/tutorials/introduction/linux_install/linux_install.html
And then start to install the gem as below
gem install ruby-opencv -- --with-opencv-dir=/usr/local.
Now it will work.
Typically the Ruby opencv gem needs to compile native extensions, including the opencv tools, the sqlite database, the python language, openssl networking, and possibly access to your system's compiler such as gcc.
These extensions are generally easiest to diagnose by using sudo.
Try this if you can:
sudo gem install ruby-opencv -v '0.0.14'
Also, you may want to try changing from using rvm to using ruby-build.
Can you please edit your question, and add the results of the log file?
cat /home/k2/.rvm/gems/ruby-2.1.2#rails4/extensions/x86_64-linux/2.1.0/ruby-opencv-0.0.14/gem_make.out
Have you already installed OpenCV successfully on its own?
You can install OpenCV with these instructions: http://docs.opencv.org/doc/tutorials/introduction/linux_install/linux_install.html
If you can install OpenCV, that may help verify you have most of the pieces you need for the Ruby gem.

'gem install [name of gem] --pre' is not updating my system gems

I am a newbie when it comes to working with gems so pardon me if i'm getting my facts wrong.
I want to update Bundler from v1.3.5 to the latest version (v1.5.3) so I tried doing:
sudo gem install bundler --pre
the command line outputs:
Fetching: bundler-1.5.3.gem (100%)Fetching: bundler-1.5.3.gem
Successfully installed bundler-1.5.3
Parsing documentation for bundler-1.5.3
Installing ri documentation for bundler-1.5.3
Done installing documentation for bundler after 4 seconds
1 gem installed
but when I do gem list or bundle --version, it shows that i'm still using the old version (v1.3.5). This goes to all my other gems. I tried updating Susy, Sass and Compass the same way, but it doesn't get updated even though it says that it was installed successfully.
Any ideas? TIA
Fixed it. It seems that if you add sudo when installing gems, it installs the gem on a different directory from the one used when you don't use sudo. I saw this when I did sudo gem list and it displayed different results from a normal gem list command.
To be able to add gems without sudo I just did chown -R [current_user] [ruby_directory]
Run bundle update on the command line. This will update your gems in your app.

Ruby on Rails gem problem

I'm using Ruby on rails (RubyMine) and I try starting my project.
Which tells me the error "Could not find gem 'mysql2 (~> 0.2.6, runtime)' in any of the gem sources listed in your Gemfile. (Bundler::GemNotFound)".
I've done sudo gem install mysql which gives me
"Error installing mysql:
ERROR: Failed to build gem native extension.
Gem files will remain installed in /var/lib/gems/1.8/gems/mysql-2.8.1 for inspection.
Results logged to /var/lib/gems/1.8/gems/mysql-2.8.1/ext/mysql_api/gem_make.out
"
What should I do?
You're probably missing the development headers for MySQL. Often this is shipped as an optional package to install. You may need to install mysql-dev or mysql-devel depending on your package manager.
You might also be missing a compiler, so check that you have the required dependencies for gem such as make and gcc.
You might be missing the Ruby development headers as well. On my Ubuntu 11.04 box I have the following aptitude package which is needed for native gem compilation:
ruby1.9.1-dev

Resources