"rails new [Blah]" No such file - ruby-on-rails

So I'm new to Ruby and also to Rails. I have recently installed Ruby on Arch Linux.
It was mostly all fine any happy except for a few errors here and there but now when I try initializing a new rails app using rails new AppName I get the error
bash: /home/[username]/.gem/ruby/2.3.0/bin/rails: No such file or directory
I've tried creating a file and directory called rails in but get more errors.
reinstalling rails same outcome
reinstalling ruby same outcome
following any other dependencies at install also leads no wear.
Ask for any info you may need.
Thanks in advance
UPDATE
installing of gems is now stopped by a common error
$ gem install rails
Building native extensions. This could take a while...
ERROR: While executing gem ... (Errno::EACCES)
Permission denied # rb_sysopen - /usr/lib/ruby/gems/2.3.0/extensions/x86_64-linux/2.3.0/nokogiri-1.6.8/gem_make.out
and the same when I try install nokogiri

ok first check that you installed both ruby and rails well
ruby -v
and
rails -v
so if you get a respond to that you're all good
go to the place you want to create your folder att
rails new appname
then
cd appname
if that doesn't work try to generate anything
rails generate controller appname
if the generate works then your rails is ok if not then you might want to add the rails to your environment variable path.
You installed ruby on your computer. However the path is not recognized yet on it. To add it you can do this . if you are using windows my computer right click and then chose advanced system settings -> advanced at the bottom environment variables system variables PATH and then add the the path to your ruby bin folder. I am sorry i don't have enough reputation so can't add pictures but reading this will solve your problem

The overall problem is a lack of permissions to /usr/lib/ruby/. This can be fixed with
sudo chmod 777 /usr/lib/ruby

Related

Adding ruby on rails to an existing react native app

Background
I'm developing a React Native app for the first time. I've gotten to the point where I need to start working on the back end and I'm going to use Ruby on Rails to do that. I've installed Ruby and SQLite3, and I've successfully added Ruby to my project.
Problem
As of right now, when I try to install bcrypt and jwt to the Gemfile in the project, I ran gem install bcrypt/jwt and that seemed to work, but when I try to run bundle i get an error: "Could not locate Gemfile". I am certain the Gemfile is in the directory I'm running the commands in, as I can see it in VS Code and also going down the path in C:/, etc.
Question
Can I actually add Ruby on Rails to an existing project? What could be the cause of this issue?
Thanks a lot!
If you have created a new Rails-App via rails new myapp you can cd into this directory and call bundle install.
rails new myApp && cd myApp && bund
Please check that you are in the correct directory. If you are sure that you are in the right directory then check your current rails version with rails --version.
Make sure you are in the project directory before running bundle install. For example, after running rails new myproject, you will want to cd myproject before running bundle install.
gem install - like npm install -g, programm to fetch gems,
bundle is fetching list of gems from Gemfile in your app(current folder), like package.json (not sure about naming)
1. Can I actually add Ruby on Rails to an existing project?
Yes, sure. You have a lot of variation to do that
here link the good article how create rails-react app, then you can move your front end part to react folder in the new rails application.
you can create new rails as separated application, in folder what you want as API with option rails new your_app_name --api, then send requests from react app directly to rails app port or IP(it is harder to implement, but I think it is right solution).
2. What could be the cause of this issue?
it is possible because you do not have rails app do not exist
you do not have Gemfile in your folder.

copies a rails app to a new computer: rails command not found

I have just set up ruby and rails on a freshly installed freeBSD. It works great. I can do rails new blabla mv into blabla and do rails s and it just works.
I had an up and running rails app on another computer. I copied the repertory that contained the app to the new computer running freeBSD. However, when I mv into that repertory of the rails app and to rails server I get -bash: rails: command not found
I have tried creating a new app with the same name and let rails create all the repertories and then copy the files of the existing rails app therein but no success.
I can run rails -v and rails s from within any repertory and get correct answer, but when I move into that specific repertory I get that command not found.
You're probably using a ruby version manager I suspect (rbenv/rvm)? Check the ruby version in your Gemfile (top of the file). It probably isn't the same as the ruby version you have installed. If you're using one of the above mentioned version managers than install the correct ruby for your rails project. After that you can do a gem install bundler in the project directory and after run bundle install which will install rails and all dependencies.
Which version you are using? It happens with earlier versions. Try updating your gems and bundler. And try again. Hope it helps.
Did you try running bin/rails s? I think tha you need run bundle install too.

Rails command not working on Windows command line

I installed Ruby and Rails and set-up the PATH to "C:\Rails\Ruby2.3.0\bin", but when I try to run commands with rails, I get the error message:
The System cannot find the path specified.
I am able to run commands using ruby, and rails works if I use GitBash. How do I make it work on my normal command line?
Had the same problem here, installed the same way. Couldn't even run rails commands on GitBash, only way was going in C:\Rails\Ruby2.3.0\binthrough cmd and typing, for example, ruby rails new projectname. The rails new projectnamewouldn't work even in these conditions.
What I did was going in the Command Prompt with Ruby and Rails and entered gem install rails (which did not work on cmd). I also did gem install bundle. Both installed successfully and that fixed all consoles for me: cmd, GitBash (wasn't working for me), Command Prompt with Ruby and Rails and even cmder works with Rails now.
Hope this helps you.
Cheers.
If it's a simple question of locating the rails executable on Windows, then on later installs that use msys64 instead of DevKit, you'll find rails at the following folder:
c:\msys64\o-rdoc
Add this to your PATH or execute from that folder.
Your path may vary on 32-bit systems or if you changed the default install folder.

Beginning Ruby on Rails in Linux Mint

This may sound very basic to many of you. I have just started a Ruby on Rails tutorial in Linux. I'm very new to the Linux OS. I have installed a rvm. But I am unable to install Rails. It's saying "cant load such file --zlib". And I can see two source files for Ruby. Not sure if I have two Ruby installed.
Just take a note that you have selected the correct build system:
"Tools -> Build System -> Ruby"
Then press CTRL+B.
This should work.
You can execute .rb file in sublime using ctrl + b.
It seems you are a bit confused about how Ruby on Rails work.
Sumblime can run your ruby code but not on Rails stack.
My suggestion it's to work always with an open terminal on the directory of your rails application.
Let's assume you created a new rails project as
rails new helloWorld
The rails generetor will create a subfolder helloWorld.This will be your working directory in the terminal.
So you have to do:
cd helloWorld
and then
rails s
It will run your rails application on an embedded server on localhost:3000 by default.
What method did you use to install ruby?
If you compiled from source you may need to do
sudo apt-get install libssl-dev
And then recompile ruby
Otherwise, you may not have the most recent version of Rubygems
Try:
go to https://github.com/rubygems/rubygems/releases/tag/v2.2.3
download rubygems-update-2.2.3.gem
call the directory where the file was dl'ed, then
gem install rubygems-update-2.2.3.gem
update_rubygems --no-ri --no-rdoc
rubygems --version #Should show 2.2.3
gem install rails

Do I have to install Rails on every new project?

This is a beginner-level question.
I'm using Ubuntu 12.04
I copied a project (created on Rails 4 using the rails new command) from Dropbox to my local environment, where I have previously install Rails 4 and up-to-date Ruby and RVM, went to project's directory, typed rails server and got
The program 'rails' is currently not installed. You can install it by typing:
sudo apt-get install rails
I ran gem install rails instead.
Will I have to run gem install rails on every project's directory? I thought the Rails install was a general and accessible on my whole environment.
The project was created using the same Ruby version, but on a MacOS X system.
The project is a static web brochure and has no database configuration.
Thank you in advance.
Make sure you're using the correct version of Ruby - the same version that you'd installed Rails into - with rvm list.
You likely have two of them (since you have such an issue) - the system Ruby and the RVM-installed Ruby. And likely RVM didn't engage and hook up the correct path to the rails executable, thus the error.
This should fix the issue:
rvm use whatever-ruby-you-had-installed-rails-into
Where whatever-ruby-you-had-installed-rails-into is a string like ruby-2.1.0-p0 taken from the rvm list output.
To make RVM retain Ruby version for the project.
echo whatever-ruby-you-had-installed-into >.ruby-version
in your project's path.
So after a few hours of testing, reproducing the problem, and reading (the other answers inclusive) I got the solution as follows:
Short answer: No. Rails needs to be installed only once.
Long answer: This problem occurred because of a default setting on Terminal that prevents the system from using RVM installations of ruby and rails. The solution is to integrate RVM with gnome-terminal as described in the RVM website.
With terminal window active, go to the menu at the top bar
Edit > Profile Preferences > Title and Command tab
Check the Run command as a login shell box
Restart Terminal and make sure your gemset and ruby version are set
rails server should now work as expected (you might be prompted to run bundle install before Rails can actually run fine, follow the promtp).
I am still learning to work with Ruby on Rails, so any inputs, clarifications, or additional information on the issue is more than welcome.
You don't have to install Rails on every project, but the gems that you need for that project.
With bundle install you install all the gems that you specify in Gemfile.
If you want to avoid reinstall the gems every time you change project, I suggest you to have a better look to RVM: it has got an opt called gemset (https://rvm.io/gemsets), if you use it you just need to switch your gemset:
rvm gemset use yourgemset
I hope it can help you.

Resources