WSL: Unable to execute rails, cannot find it even though it's installed

I installed Ruby 2.3.1 with RVM and created a specific gemset for my project. I did a bundle install. there were some issues with the gems but I got through them and got a full bundle install. But when I run rails s I get

The program 'rails' can be found in the following packages:
 * ruby-railties-3.2
 * ruby-railties-4.0
Try: sudo apt-get install <selected package>

And when I run bundle exec rails s I get

bundler: command not found: rails
Install missing gem executables with `bundle install`

But when I do a gem list | grep rails you can see I have it installed and am in the correct gemset

autoprefixer-rails (6.3.6.1)
capistrano-rails (1.1.6)
coffee-rails (4.1.1)
dotenv-rails (2.1.1)
factory_girl_rails (4.7.0)
haml-rails (0.9.0)
jquery-rails (4.1.1)
rails (5.0.0.rc1)
rails-deprecated_sanitizer (1.0.3)
rails-dom-testing (1.0.7)
rails-html-sanitizer (1.0.3)
rails_layout (1.0.29)
rspec-rails (3.1.0)
sass-rails (5.0.4)
sprockets-rails (3.0.4)

Any suggestions would be welcome.

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 38 (7 by maintainers)

Most upvoted comments

Go to you config/environments/development.rb and comment out the last line, something about watching files and listen gem. can’t remember from the top of my head the exact wording, but it is the last line of config

this is new a new method that rails uses to watch changed files, but it doesn’t work on WSL

I think guard gem will also fail because of this

I saw this when using Rails Console and Rails Runner. Firstly: bundle install --binstubs fixed it but that will screw up your version control if you’re on Rails >= 4. To get around it this is what I did (according to the advice from Rails): bundle config --delete bin rake rails:update:bin git add bin

Hope this helps someone.

I think this might be because you haven’t sourced rvm’s script. Or alternatively, maybe it’s because bash isn’t executed as a login shell (which IMHO, it should be). Try fixing this by running bash --login or zsh --login. I had some issues getting this to run directly from the shortcut, but a kludge I’ve used is to just have the last line of my .bashrc be exec zsh --login. This is probably a bad idea, so this tip is provided without any warranty 😄

  # Use an evented file watcher to asynchronously detect changes in source code,
  # routes, locales, etc. This feature depends on the listen gem.
  config.file_watcher = ActiveSupport::EventedFileUpdateChecker

This is the part that needs to be commented/removed, then it seems the rails server does run through bundle exec rails s. I’ll need to do more testing but it seems to be something!

If you have closed the terminal. I found out that you need to run: /bin/bash --login

then gem works again. I used rvm to install ruby. Also i found out that you must choose default for anything to work rvm use 2.3.1 --default

for bundler to work i used following command: find ~/.bundle/cache -type d -exec chmod 0755 {} + it gets rid of the problem where it says world writable and not sticky.

Spring does not seem work right, atleast not for me, but you can use: rails new appname --skip-spring and you should be able to run generate controllers and models. Bad news is that you need to restart the server all the time, maybe not when you change in the views, but if you change something in lets say routes, it requires a restart. Luckily rails restart should be enough.

The problem for with the file watcher just comment out: # config.file_watcher = ActiveSupport::EventedFileUpdateChecker inside the {projectfolder}/config/envoirments/development.rb

Nothing fancy… IIRC:

rvm install 2.3.1
rvm gemset create test
rvm use 2.3.1@test
gem install rails #4.2.6
rails new test
cd test
rails generate controller welcome index

(you’ll have to do the workaround I mentioned with the sticky bit to get rails to work)

I’m getting the same weird error about spring. To work around it just use DISABLE_SPRING=true before your command line.

@mikedhart - I had the same error when running rails c and your advice fixed my problem. Thanks!

check the generated binstubs. what happens if you run something like bin/rails console?