New Discussion

Notifications

You’re not receiving notifications from this thread.

Setup Windows 10 Discussion

236
General

Hi,

I got all the way through this so thanks for the walk through! I run "rails server -b 0.0.0.0" and the server boots fine but when I go to localhost:3000 in the browser, the browser icon spins but the server does not respond. Has anyone seen this before?

For any newcomers experiencing this issue:

Run ifconfig then select the appropriate ipv4 ---> inet addr address for your ethernet adapter (Typically eth0).

Example:

eth0 Link encap:Ethernet HWaddr 30:9c:00:a0:93:b5
inet addr:192.168.1.236 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::d400:af9d:a16e:0000/64 Scope:Global
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

Then once you find your local IPV4 you can go to your browser and type your address plus the appropriate port, in my case 192.168.1.236:3000

Which will succesfully connect you to your Ubuntu bash rails server on your local machine!

As for anyone experiencing the issue of rails or gem commands not working after exiting and re-entering bash; you need to ensure you are running shell commands, you can acheive this by running exec $SHELL and possibly the few commands prior as laid out in the Installing Ruby portion of this tutorial.

IMPORTANT UPDATE (9/29/2018):
Per the instructions HERE, nate clarifies something extremely important regarding switching users via su. In order to succesfully execute .profile you must use su - user, where su simply switches users, while su - ... is an alias to su user --login || su user -l which then allows you to succesfully execute gem, rails, and bundler commands whereas they would normally be unavailable (command not found). This is a nicer way of doing things, rather than my solution of running exec $SHELL every time, one less command! Woohoo!

Cheers!

As of 9/28/2018

I've worked it out now. It seems that thin was the problem. I switched to webrick and the app now runs perfectly. I don't exactly no what the problem was with thin but this solution works for now!

So cool. I have been waiting for you to write this :)

This is great tut- based on it I installed rails 5 and ruby 2.3.1. created new test app and after rails -s I have something like this: => Booting Puma
=> Rails 5.0.0 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
Exiting
/root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rb-inotify-0.9.7/lib/rb-inotify/watcher.rb:74:in `initialize': Invalid argument - Failed to watch "/root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/locale": the given event mask contains no legal events; or fd is not an inotify file descriptor. (Errno::EINVAL)
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rb-inotify-0.9.7/lib/rb-inotify/notifier.rb:190:in `new'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rb-inotify-0.9.7/lib/rb-inotify/notifier.rb:190:in `watch'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rb-inotify-0.9.7/lib/rb-inotify/notifier.rb:204:in `watch'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/listen-3.0.8/lib/listen/adapter/linux.rb:32:in `_configure'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/listen-3.0.8/lib/listen/adapter/base.rb:45:in `block in configure'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/listen-3.0.8/lib/listen/adapter/base.rb:40:in `each'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/listen-3.0.8/lib/listen/adapter/base.rb:40:in `configure'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/listen-3.0.8/lib/listen/adapter/base.rb:63:in `start'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/listen-3.0.8/lib/listen/backend.rb:28:in `start'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/listen-3.0.8/lib/listen/listener.rb:67:in `block in <class:listener>'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/listen-3.0.8/lib/listen/fsm.rb:120:in `instance_eval'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/listen-3.0.8/lib/listen/fsm.rb:120:in `call'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/listen-3.0.8/lib/listen/fsm.rb:91:in `transition_with_callbacks!'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/listen-3.0.8/lib/listen/fsm.rb:57:in `transition'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/listen-3.0.8/lib/listen/listener.rb:90:in `start'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/evented_file_update_checker.rb:90:in `boot!'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/evented_file_update_checker.rb:61:in `initialize'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/i18n_railtie.rb:59:in `new'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/i18n_railtie.rb:59:in `initialize_i18n'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/i18n_railtie.rb:15:in `block in <class:railtie>'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/lazy_load_hooks.rb:44:in `each'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0/lib/rails/application/finisher.rb:65:in `block in <module:finisher>'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0/lib/rails/initializable.rb:30:in `instance_exec'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0/lib/rails/initializable.rb:30:in `run'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0/lib/rails/initializable.rb:55:in `block in run_initializers'
from /root/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:228:in `block in tsort_each'
from /root/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
from /root/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:431:in `each_strongly_connected_component_from'
from /root/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:349:in `block in each_strongly_connected_component'
from /root/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `each'
from /root/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `call'
from /root/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `each_strongly_connected_component'
from /root/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:226:in `tsort_each'
from /root/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:205:in `tsort_each'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0/lib/rails/initializable.rb:54:in `run_initializers'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0/lib/rails/application.rb:352:in `initialize!'
from /root/myapp/config/environment.rb:5:in `<top (required)="">'
from /root/myapp/config.ru:3:in `require_relative'
from /root/myapp/config.ru:3:in `block in <main>'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-2.0.1/lib/rack/builder.rb:55:in `instance_eval'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-2.0.1/lib/rack/builder.rb:55:in `initialize'
from /root/myapp/config.ru:in `new'
from /root/myapp/config.ru:in `<main>'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-2.0.1/lib/rack/builder.rb:49:in `eval'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-2.0.1/lib/rack/builder.rb:49:in `new_from_string'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-2.0.1/lib/rack/builder.rb:40:in `parse_file'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-2.0.1/lib/rack/server.rb:318:in `build_app_and_options_from_config'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-2.0.1/lib/rack/server.rb:218:in `app'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0/lib/rails/commands/server.rb:59:in `app'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-2.0.1/lib/rack/server.rb:353:in `wrapped_app'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0/lib/rails/commands/server.rb:124:in `log_to_stdout'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0/lib/rails/commands/server.rb:77:in `start'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0/lib/rails/commands/commands_tasks.rb:90:in `block in server'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0/lib/rails/commands/commands_tasks.rb:85:in `tap'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0/lib/rails/commands/commands_tasks.rb:85:in `server'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0/lib/rails/commands.rb:18:in `<top (required)="">'
from /root/myapp/bin/rails:9:in `require'
from /root/myapp/bin/rails:9:in `<top (required)="">'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-1.7.2/lib/spring/client/rails.rb:28:in `load'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-1.7.2/lib/spring/client/rails.rb:28:in `call'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-1.7.2/lib/spring/client/command.rb:7:in `call'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-1.7.2/lib/spring/client.rb:30:in `run'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-1.7.2/bin/spring:49:in `<top (required)="">'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-1.7.2/lib/spring/binstub.rb:11:in `load'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-1.7.2/lib/spring/binstub.rb:11:in `<top (required)="">'
from /root/.rbenv/versions/2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /root/.rbenv/versions/2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /root/myapp/bin/spring:13:in `<top (required)="">'
from bin/rails:3:in `load'
from bin/rails:3:in `<main>'
Any ideas what should I do ?

According to this site[1] you can omment out "config.file_watcher = ActiveSupport::EventedFileUpdateChecker" in this file, config/environments/development.rb

[1]:https://github.com/rails/ra...

The main issue here is that inotify has been completely broken in WSL. So even if you disable listeners, tools like Guard won't work. Insiders are soon getting a partial fix, whereby files changed within WSL itself can be watched without errors.

Here's the test. First install inotify-tools, which give you some command line programs to monitor files:

$ sudo apt-get install inotify-tools

Then attempt to watch any file from the command line:

$ touch testfile.txt && inotifywatch testfile.txt
Establishing watches...
Failed to watch ./testfile.txt: Invalid argument

Note that's the same error that rb-inotify reports above.

Github issues:
https://github.com/Microsof...
https://github.com/Microsof...

I get the error like : `sudo: setresuid() [1000, 106, 1000] -> [-1, 0, -1]: Operation not permitted` when I try to create new postgres user. Is it going to be fix in the nearest feature?

Abhinav Tripathi Abhinav Tripathi

why does this blog have no support?
people are facing multiple issues!

Kevin Méndez Kevin Méndez

Hi, friend! You can install postgres in windows. To connect the app you only need a port of the database (I had the same issue at the beginin).

Stefan Cardenas Stefan Cardenas

I'm getting the same error and can't figure out how to get around it. I've tried uninstalling and reinstalling Postgresql to no avail. Any thoughts?

How were you able to get the terminal to let you copy the SSH key so that you could paste it into GitHub? Copy and paste is not working for me using shortcuts or the mouse, and there is no menu that I can see.

RIght click on the Ubuntu icon, go to properties and check the boxes under Edit Options and text selection

I would just suggest taking a look at cmder -- This tool is a terminal lifesaver for me on Windows. It is highly configurable. By default, it adds git and some linux tools to cmd, the default shell it uses, but also allows you to use any shell (MING64, Git Bash, PowerShell, the new Bash/Ubuntu for Windows).

Today I tried getting on with the default Bash for Windows which uses the older cmd terminal, but I went bananas. Cmder gives you the text tools you need!

that link is malware now

Thanks, removed the link. 👍

Łukasz Fuszara Łukasz Fuszara

I run Rubinius on Windows 10 Bash.

Brian Arpaio Brian Arpaio

When I run "rails new testApp -d mysql" I get back
"Errno::ENOMEM: Cannot allocate memory - sudo -p "

Your user account isn't allowed to install to the system Rubygems."

Anyone have any ideas where I went wrong?

Brian Arpaio Brian Arpaio

Fixed it - had to do a fresh install of everything from outside of the firewall at my office.

Tried re-installing and now the error I get is
"Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory: /home/barp/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/debug_inspector-0.0.2/ext/debug_inspector
/home/barp/.rbenv/versions/2.3.1/bin/ruby -r ./siteconf20160805-549-tt92si.rb extconf.rb
Cannot allocate memory - /home/barp/.rbenv/versions/2.3.1/bin/ruby -r ./siteconf20160805-549-tt92si.rb extconf.rb 2>&1"

I received an error "There was an error while trying to load the gem "uglifier". Gem Load Error is: Could not find a JavaScript runtime." Any ideas?

Kai Dorschner Kai Dorschner

Install node.js in the Linux subsystem maybe?

Paulo de Tarso Paulo de Tarso

After I close the terminal I lost all the settings that I had installed following this tutorial. I will try install it again but I fear that the same happen again. What should I do to prevent it?

Paulo de Tarso Paulo de Tarso

In fact, some commands stoped working since I closed the bash: rails new, rake test, bundle etc.

strangebiscuit strangebiscuit

I'm able to go through this whole tutorial for Windows 10 bash and get everything listed here working (using rvm currently). I get through all the final steps without error, got a working server, etc...

But I'm trying to follow a basic "hello world" tutorial ( found here: http://iridakos.com/2013/11... ) and when I try "rails generate controller pages" I get: "Error: Command 'rails' not recognized" as well as an info section on "Usage: spring COMMAND [ARGS]" and "Usage: rails COMMAND [ARGS]"

I'm confused as to how it could possibly say 'rails' is not recognized. I can do "rails -v", I can do "rails new", I can do "rails server", etc...

Anyone have any advice? I've tried this like 6 times now (resetting my entire linux subsystem after each failed try) using both rvm and rbenv and I end up stuck at this point every time. Any pointers as to where I'm going wrong would be greatly appreciated...thanks!

I was having this same issue and abandoned my attempt. If someone understands what's at hand here, that would be great.

I posted this in the long chain of comments that follows this thread, I thought I'd add it back up here for you and future folks too.

This guy has a solution https://github.com/Microsof...

```
bundle config --delete bin
rake rails:update:bin
git add bin
```

I've successfully tested it using WSL/Bash on Win10, with the instructions posted above using the RVM install, after running `bash --login` to ensure interactive shell.

I hope this helps you out!

Anthony Coffey Anthony Coffey

THIS IS AMAZING!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

I love you <3

I agree with Anthony on this. I have the best of both worlds (solid windows gaming on a ridiculously fast machine and still have an ubuntu bash shell).

This is really perfect Chris. You're awesome.

radical_primate radical_primate

Excellent!! Thanks so much for this. Up and running without a hitch after first updating to Windows 10 Anniversary. You don't need to be an Insider to update now.

I hope WSL is the real deal...I've had several fits and starts trying to get going with rails on a windows machine.

Suggestion for newbies: rather than create myapp in your linux directory, switch to your windows directory, then create myapp there.

At that point you'll have ready access to work on the myapp files via your IDE

Thus, for final step, type this at the prompt $: cd /mnt/c/Users/you

Then in this director type $: rails new myapp

Got things rolling smoothly with this article. Not sure if anyone else had this issue but ruby took a really long time to install. I thought it was hanging but figured I'd give it a chance and left it running when I went to bed. In the morning it was done so slightly longer than 45 minutes for me!

It definitely can take a while sometimes. Depends on how powerful your computer is and stuff.The good news is you rarely need to do it so once it's done, you will be set for quite a while!

Dale D. Smith Dale D. Smith

I installed everything. Started the server. Went to the webpage and I got the error:
Cannot load `Rails.application.database_configuration`: No such file or directory @ rb_sysopen - /home/dale/myapp/config/database.yml

Also I tried a cat config/database.yml and received a no file or directory error.

I look in the directory and the file is there.

Frustrating. Can't find a solution. Anyone?

Hey Dale, you'll probably need to create that file if your Rails app doesn't have one. Some details on that file: http://edgeguides.rubyonrai...

Peter Truchan Peter Truchan

Thank you! I would suggest to add to postgresql installation quide, that it is possible to make it running by installing postgres directly on windows (https://www.postgresql.org/... - prefferably version 9.3.

Another issue I had is with Thin rails server. You have to use webrick by setting enviroment variable: `export RACK_HANDLER=webrick` and then run `rails s`

PS: I am going to try to develop our application on windows with this setup, I will post my experience then. Our application is for chess players and tournament organisers - https://www.swips.eu

Did you configure anything after the postgresql installation? I tried to follow the instruction here: https://github.com/Microsof... but it didn't work for me. Do you have any tips/comments that could help? Thanks

Which PGsql version did you guys download for corrresponding ruby version like i have downloaded ruby version 7 as the above guide said but i have installed pgsql version 14 is it compatible ? for ruby v7 to pair with pgsql 14??

Unfortunately as of now, when running "sudo -u" there is a bug in the Windows Bash which states: `sudo: setresuid() [1000, 1000, 1000] -> [-1, 0, -1]: Operation not permitted`

Official bug here: https://github.com/Microsof...
Of course you can work around that by using `sudo su USER`.

Otherwise a really nice tutorial with good hints (especially the `chmod +t -R ~/.bundle` one)! Million thanks!

I seem to have trouble sending http requests from my rails server on my windows 10 ubuntu subsystem, whereas people working on their OSX or normal linux have no such problem even with the same code. I keep getting a Net::OpenTimeout (expiration expired) exception no matter what type of http request I do. Has anyone experienced this as well and does anyone know why this might be happening?

@petertruchan:disqus How exactly did you get the postgresql installation to work? I followed the instruction i found here: https://github.com/Microsof... but it didn't work. Any tips/comments would be appreciated. Thanks

Tecnologia Senatur Tecnologia Senatur

Hi!. I have a problem running a rails server. It's seems that a Thin Server is up and running, but not listening on port 3000

This picture will show you my situation. Please help me!.

J. Pablo Fernández J. Pablo Fernández

hey .. did all the things till the final step /
i had some problem so closed the bash screen and turned on again
now when i type ruby -v .. its says it to install same goes for rails everything

so .. far i dnwld everythng is gone ah ???

i dont understand help me

it took nearly 4 hrs fr me to reach final step

It's likely that everything is installed but your terminal didn't automatically load rbenv again. Double check and make sure that you followed all the rbenv lines correctly to echo the lines into your .bashrc file.

great article , someone know how to install solidus ecommerce on w10 ussing bash ubuntu? thks

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory:
/home/rakis/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/byebug-9.0.6/ext/byebug
/home/rakis/.rbenv/versions/2.3.1/bin/ruby -r ./siteconf20161113-24750-68ud34.rb
extconf.rb
Cannot allocate memory - /home/rakis/.rbenv/versions/2.3.1/bin/ruby -r
./siteconf20161113-24750-68ud34.rb extconf.rb 2>&1

Gem files will remain installed in
/home/rakis/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/byebug-9.0.6 for
inspection.
Results logged to
/home/rakis/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/extensions/x86_64-linux/2.3.0-static/byebug-9.0.6/gem_make.out

An error occurred while installing byebug (9.0.6), and Bundler cannot
continue.
Make sure that `gem install byebug -v '9.0.6'` succeeds before bundling.
run bundle exec spring binstub --all
bundler: command not found: spring
Install missing gem executables with `bundle install`

Brilliant - all worked v smoothly, like someone else said installing ruby 2.3.1 took ages. You may also need to install rmagick - to do this type sudo apt-get install libmagickwand-dev imagemagick

Beluan Fil Joseph Qu Beluan Fil Joseph Qu

I got the problem, i'm following your tutorial, but this result after running rails new myapp -d mysql

There was an error while trying to write to
`/home/user/.bundle/cache/compact_index/rubygems.org.443.29b0360b937aa4d161703e6160654e47`.
It is likely that you need to grant write permissions for that path.
run bundle exec spring binstub --all
bundler: command not found: spring
Install missing gem executables with `bundle install`

so how do we find the root directory where all the created apps are located?

Brian Gilbank Brian Gilbank

It will be here: "C:\Users\Your Name\AppData\Local\lxss" to access your projects you will navigate to: "C:\Users\Your Name\AppData\Local\lxss\home\then your new Ubuntu username"

J. Pablo Fernández J. Pablo Fernández

Any ideas how to access that Ruby binary from Windows? For example, how do I use it as the RubyMine Ruby.

J. Pablo Fernández J. Pablo Fernández

Serving static files with webrick inside WSL seems to be as slow as it was on Windows. Have anybody experience this? any solutions?

dan setengahmanusia dan setengahmanusia

please explain to me, i still don't understand, why we don't install rails just using railsinstaller, or some simple easy installer else,,

Rails dev environment is not native on Windows, which is why you have to go through all the hassle.

I believe this guy actually reuses some other people's article and copy pasted.After installing ruby-build, when you do an rbenv install a specific version, Bash on Windows cannot create directories for installing the ruby version.

Nope, wrote it myself, but things are constantly changing with Bash on Windows so these instructions break often.

After installing everything correctly, I received a "This site can't be reached" error for localhost:3000

Any suggestions?

Slava Titorovich Slava Titorovich

ALERT !
© If you're using Windows Subsystem for Linux then there are currently some limitations on file system notifications that mean you should disable the spring and listen gems which you can do by running rails new blog --skip-spring --skip-listen.
http://guides.rubyonrails.o...

I know this is a bit of an older post, but it is one of the few places where someone is doing, more or less, what I'm trying to do. My question is, has anyone successfully done this with jruby? I have tried installing jruby 9000 in my home directory, in the multi-user setup (usr/bin/jruby which are symlinks pointing to /usr/lib/jruby/bin), and using RVM in the home directory. In all cases I get to the point where jruby is installed and seems to run properly, but the gem command simply doesn't work. When I try to run "gem install rails" or "gem install bundler" or "jruby -S gem install..." I get "Unable to download data from https://rubygems.org/ - timed out"

is it possible to use sublime text somehow? Just wondering

Daniel Morgoth Kent Daniel Morgoth Kent
Oluwole Oyekanmi Oluwole Oyekanmi

Thanks for this.. It was quite helpful.

Dmitrii Evdokimov Dmitrii Evdokimov

As for now this Bash is open for every PC with 64-bit Windows 10 Anniversary Update build 14393 (1607) or later - https://msdn.microsoft.com/...
So I install Ruby 2.4.1 from sources (and run Jekyll 3.4.3).

Incase you're not able to do rake db:migrate with pgsql try this .

I installed pgsql on local windows and not on ubuntu bash
Then did the following:
Go to you config/environments/development.rb and comment out The Line config.file_watcher = ActiveSupport::EventedFileUpdateChecker,
After this run - rails s or rake db:migrate.

This worked for me and is pretty fast too.
Earlier I was using Vagrant (VM) and this (Ubuntu on bash) is faster than vagrant method,
Just my opinion, Hope it helps :)

Brian Gilbank Brian Gilbank

What version of postgres did you install on windows?

Alix Bear Kearney Alix Bear Kearney

It looks like this does not work currently if you've been upgraded to xenial. Specifically, ruby does not appear to install correctly if you close the bash session, and you have to rerun the rvm script every time, in addition to not being able to install the rails gem at all.

Jonatan Jansson Jonatan Jansson

so go for rbenv?

When going to locahost:3000 in the browser I get, json response as it it a api:

{"status":500,"error":"Internal Server Error","exception":"#\u003cRuntimeError: Cannot load `Rails.application.database_configuration`:\nCould not load database configuration. No such file - [\"config/database.yml\"]\u003e

I have one problem on install postgresql on create user.
here is command:
malin@XMAN:~$ sudo -u postgres createuser malin -s
output: sudo: unable to resolve host XMAN
output: sudo: setresuid() [1000, 106, 1000] -> [-1, 0, -1]: Operation not permitted
how can I fixed it? Thank you.

Hi,
can you do a tutorial to explain how it's possible to configure rubymine to edit a project? (project in ubuntu /home/User). I would like to use Rubymine i have install on windows to edit code in ubuntu subsysteme.

Thanks a lot!

did you get the answer for this?

Chris it would be interesting to update the tutorial for Windows 10 Creators Update considering the many new updates and improvements the Windows Subsystem for Linux has received! ;) https://blogs.msdn.microsof...

I will try doing that! I've gotta get my Windows 10 install back working again. :S

james chalmers james chalmers

My install works fine until 'gem install bundler' when I get this error:'/home/james/.rbenv/versions/2.4.0/bin/ruby: symbol lookup error: /home/james/.rbenv/versions/2.4.0/lib/ruby/2.4.0/x86_64-linux/socket.so: undefined symbol: parse_numeric_port'.
I'd appreciate any help as I really want to get WSL to work.

rvm works

Hello,

Thanks for the tutorial. It really helped me to get my basic setup up and running.
Thou I did have to fiddle around to get a few things working.
I should note that 5/14/17 I was not able to do

sudo -u postgres createuser YOURUSER -s

instead I had to use

sudo sudo -iu postgres createuser YOURUSER -s

due to -u not working at the time on WSL. Also I had to start the postgresql service before creating the user with

sudo service postgresql start

Hope this comments help people trying to install it later.

Thanks again for all your help and to all the RoR community, I just spent the last few days until I had my successful attempt at installing everything I wanted on WSL (yeah there were 4, I am now familiar with lxrun.exe /uninstall /full and lxrun.exe /install to reset the entire linux subsystem :P).

PS:
I would like to see added to the tutorial some information on installing MongoDB. For the moment I will just leave the link to the official tutorial https://docs.mongodb.com/ma... small comment though there are problems starting mongodb as a service so for now the only way I have found is to use sudo mongod. Also, remember to run mkdir /data/db before starting the database (that last bit is required but it is not included in the official tutorial from mongo).

JimboSliceOG JimboSliceOG

The source on my machine does not have the same path ~/.rvm/scripts/rvm

Mine is @: /usr/local/rvm/scripts/rvm

Also, The source is not persisting after exiting the terminal. And finally, it's failing when I try to start the rails server.

edit: got it working in the end, lots of patience required :)

Hello, thanks for the tutorial, however, I'm just trying to install rbenv and it has already taken 1 hour of waiting, it seems it is stuck on 'installing ruby-2.4.0...'. Should I just cancel and start afresh with rvm?

what did you do? I have same issue. Another comment mentioned he left it over night and was ready in the morning. It is crazy it takes this long. Cant imagine ruby being a huge program.

Francisco Javier Vallés Johnso Francisco Javier Vallés Johnso

I just want to share how I was able to install postgresql 9.5.
First, after running "sudo apt-get install postgresql-common postgresql libpq-dev" I got the error:

"http://archive.ubuntu.com/u... xenial-updates/main amd64 postgresql-client-9.5 amd64 9.5.7-0ubuntu0.16.04 Hash Sum mismatch"

So, as the console sugested, I executed it again adding "--fix-missing" and it worked.

Next, running "sudo sudo -u postgres createuser username -s" throwed the error:

"psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?"

which I solved by running "sudo pg_ctlcluster 9.5 main start".

Finally, trying to run "rails db:create" I got the error:

"new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII)"

The solution for this was running:
- sudo sudo -u postgres psql
- UPDATE pg_database SET datistemplate = FALSE WHERE datname = 'template1';
- DROP DATABASE template1;
- CREATE DATABASE template1 WITH TEMPLATE = template0 ENCODING = 'UNICODE';
- UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template1';
- \c template1
- VACUUM FREEZE;

I found all the above solutions searching in Google, but I don't remember the links.

Hope it helps someone and saves them some time.

I have mysql installed on windows. Do I need to install it separately on Linux Subsystem?

How old is this guide? I ask because, as of 6/22/2017 msdn quotes:
"Languages: Javascript/node.js, Ruby, Python, C/C++, C# & F#, Rust, Go, etc.
Services: sshd, MySQL, Apache, lighttpd,"

Suggesting that ruby should have full support now?

Thanks for the tutorial!

Just a note, it's "without further ado", not "without further adieu" 😉

francesco Esposito francesco Esposito

ruby-build: definition not found: 2.4.0 ??? help me plz

James Lucas Word James Lucas Word

I get this error anytime i start the rails server or type rails -v

rails-v
/home/word/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/railties-5.1.3/lib/rails/app_loader.rb:40: warning: Insecure world writable dir /mnt/c in PATH, mode 040777
Rails 5.1.3

Great post. The install went fine, including the MySQL server installation, but when I try to connect to the MySQL server, I get the message: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

I uninstalled it (sudo apt-get remove mysql-server) and re-installed. Same error message

If I try to re-install, I get the message that the MySQL server is already installed and is the latest version. Any ideas?

The install process, despite having asked me for the root password, etc., did not automatically start the MySQL server, so the solution is simple: sudo service mysql start

i got a q. now i am o root@laptop. does this mean i am on a vertual & so i can not get actual folders and files?

Yuri de Sales Almeida Yuri de Sales Almeida

Is it possible to share folders like vagrant?

I get following error. I followed everything as mentioned in the article.
Looks like mysql db is not created.
Missed any step?

praful@MOVO-PRAFULPASA:~/myapp$ rake db:create
#<mysql2::error: can't="" connect="" to="" local="" mysql="" server="" through="" socket="" '="" var="" run="" mysqld="" mysqld.sock'="" (2)="">
Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8", "pool"=>5, "username"=>"root", "password"=>"******", "host"=>"localhost", "database"=>"myapp_development"}, {:charset=>"utf8"}
(If you set the charset manually, make sure you have a matching collation)
Created database 'myapp_development'
#<mysql2::error: can't="" connect="" to="" local="" mysql="" server="" through="" socket="" '="" var="" run="" mysqld="" mysqld.sock'="" (2)="">
Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8", "pool"=>5, "username"=>"root", "password"=>"*****", "host"=>"localhost", "database"=>"myapp_test"}, {:charset=>"utf8"}
(If you set the charset manually, make sure you have a matching collation)
Created database 'myapp_test'
praful@MOVO-PRAFULPASA:~/myapp$ mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
praful@MOVO-PRAFULPASA:~/myapp$

Not sure if you ever got it working, and I don't have a solution really, but here are some thing's I would check.

Make sure the MySQL server is actually running. If so:

Get a visual MySQL Editor, there's alot of them, make sure your database encoding is UTF8, if it's not change it. The Visual Editor just makes it easier to check thing's out. It's a bit more simple than throwing commands into a console.

Check your Firewall, and make sure it's allowing connections on the MySQL servers port/s.

Make sure you have the correct permissions/privileges, both file system permissions, and privileges to access the MySQL service. For example MySQL may have been installed with only root, or admin access allowed. try opening the bash terminal as administrator, if that doesn't work try using sudo prefixed before commands (with, and then without admin privileges on the bash process.)

Sorry I couldn't give you a concrete solution, hope you get it working.

how to open Sublime, and point them to your folders in C:\code

Max Goncharov Max Goncharov

It's very sloooow. Did anybody get this issue with all Rails/Rake commands?

Good post.

I also needed to run the following, prior to installing ruby:
sudo apt-get install -y gcc libssl-dev libreadline-dev zlib1g-dev make

james chalmers james chalmers

I installed ruby and rails correctly, but when I run my new rails app, my browser cannot connect. I must have missed something obvious somewhere. Has anyone else had this problem?

Gustavo Border Gustavo Border

Nothing wrong! Just had to start the MySQL service: "sudo service mysql start"

Is there anything wrong with just running `sudo apt install rbenv` instead of the shell script? I was having issues with the script. Only the plugins folder was cloned...

Doesn't work with me.
rails aborted!
Don't know how to build task 'v' (see --tasks)
/home/Emad/myapp/bin/rails:9:in `require'
/home/Emad/myapp/bin/rails:9:in `<top (required)="">'
/home/Emad/myapp/bin/spring:15:in `<top (required)="">'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
(See full trace by running task with --trace)

Just wanted to let you know that I just got this up and running! Thankfully I didn't have any issues. Thank you to whoever for putting this together! Great job!!!!

Thanks for tutorial, although I think you should take a moment to say if you have Windows Git you don't really need git install and likewise if you have mySQL already running as a service you don't need that either, just point database.yaml to windows instance.
Bagus, it should be called "software-properties-common" now or "python3-software-properties". Making an update for that.

Alberto, yep. You'll always need libpq-dev to compile the C extension for Ruby to talk to Postgres. 👍

Hey John, not sure why that command doesn't work from you. I just pasted in the RVM installation instructions from their website. I don't use RVM though but as long as you get the gpg keys imported, that's all you need.

Hi,

I just impressed, awesome tutorial.

I love this tutorial.

Thanks

Hey all,
So I got this running a long time ago and haven't had any issues since but now when I run any rails command I get a warning that says:
/home/user/.rbenv/versions 2.5.3/lib/ruby/gems/2.5.0/gems/railities-5.2.2/lib/rails/app_loader.rb:53 warning: Insecurable world writeable dir mnt/c/rails/project

All the stackoverflow answers are to chmod go-w /home/user but this and many derivations of this doesn't work. What else can I try?

@eliot I looked into this a few months ago and just accepted that it wasn't going to go away unless WSL was changed by Microsoft. Details at: https://github.com/Microsoft/WSL/issues/1426.

There appears to be ways to get rid of it but could introduce a security issue... I decided it was probably a bit of OCD on my behalf and to just let it go. I just find chasing these bugs means hours lost where I could actually be writing code. If you do figure out a good way please tell though.

Hi Jay!
Agreed, one can spend many hours trying to figure out the root cause of why certain things happen. In the end I found a "solution". Within the /mnt/c/ folder I rm -rf the original rails folder and then ran, "mkdir rails_sites, rails new....etc" and by deleting the old dir and creating a new one seems to have worked for the time being. It is strange this is the first time I have had any issues with the linux subsystem. Besides this minor hiccup I have really enjoyed it. I will update if I find anything else.

Hi, im using Windows 10 with the WSL, and im trying to set the Ruby Interpreter in RubyMine to the one i install using Chirs guide, using the following route /home/tensai/.rbenv/shims/ruby, the problem is that when it starts to Loading the Enviorment throws a Communication Error?

Can anyone tell how i can properly set my RubyMine to use the ruby install in WSL? using rbenv as the version manager.

I don't use RubyMine, but according to this, you might need to point to the ruby version inside the .rbenv folder instead of the shim. That way rubymine can find the gems directory correctly.

You can read the post here: https://df.tips/t/topic/326/3

Hey having a hard time debugging an error maybe someone has some insight?

gem install bundler
Fetching bundler-2.0.1.gem
/home/dj/.rbenv/rbenv.d/exec/gem-rehash/rubygems_plugin.rb:6: warning: Insecure world writable dir /home/dj/.rbenv/versions in PATH, mode 040777
Successfully installed bundler-2.0.1
Parsing documentation for bundler-2.0.1
Installing ri documentation for bundler-2.0.1
Done installing documentation for bundler after 10 seconds
1 gem installed

this insecure world writeable dir has been plaguing me if I try to set up a DB and run rake db:create or rails db:create it wont allow it to do anything any help is appriciated!

Hey Chris I'm getting the following error:
PG::ConnectionBad (could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
):

Hey Arnas,

Your Postgres server isn't running. I think most people have the best results installing Postgres on Windows and running it there, then having Rails from WSL connect to that.

how connect with wsl?

Try to export PGHOST=localhost to the bottom of your ~/.bashrc file in WSL

Hi, can anyone help me with a problem, I'm using windows 10 I have installed ruby, Ubuntu and WSL. Whenever I run my code in visual studio editor or console, I receive this warning message,
warning: Insecure world writable dir /mnt/c in PATH, mode 040777
Is there any way I can fix the problem?

i have the same problem:
i tried an older version of bundler still no change.
then i've seen this :
gem install bundler -v 2.0.1
Fetching: bundler-2.0.1.gem (100%)
/home/cod/.rbenv/rbenv.d/exec/gem-rehash/rubygems_plugin.rb:6: warning: Insecure world writable dir /home/cod/.rbenv/versions/2.5.7 in PATH, mode 040777
Successfully installed bundler-2.0.1
Parsing documentation for bundler-2.0.1
Installing ri documentation for bundler-2.0.1
Done installing documentation for bundler after 5 seconds
1 gem installed

so i think that your solution chmod +t -R ~/.bundle is not good in my case,
error
chmod: cannot access '/home/cod/.bundle': No such file or directory

any idea for an work around?
thank you

this solved my issue:
add this to the win 10 path variable:
C:\Users\”Your user” \AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\mnt

Hi Chris,
when I do 'cd'=> and after 'pwd' => home/user_name,
therefore should i change the commands from:
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL
to:
echo 'export PATH="$HOME/user_name/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL
???

Hey there! This guide was VERY useful, as every other guide on the subject I found had untold errors along the way. This one worked perfectly, up one of the very last steps after installing postgresql, where you select it using this:

rails new myapp -d postgresql

I receive this error:

/home/event/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/railties-6.0.1/lib/rails/app_loader.rb:53: warning: Insecure world writable dir /home/event/.rbenv/versions/2.6.5 in PATH, mode 040777
sh: 1: node: not found
sh: 1: nodejs: not found
Node.js not installed. Please download and install Node.js https://nodejs.org/en/download/

I installed NodeJS, but I'm still receiving this error. I tried to proceed to the next part regardless, but on this portion of code:

rake db:create

I receive this error:

could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
Couldn't create 'myapp_development' database. Please check your configuration.
rake aborted!
ActiveRecord::NoDatabaseError: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?


Caused by:
PG::ConnectionBad: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

Tasks: TOP => db:create
(See full trace by running task with --trace)

Apologies for the long help request! I'm just starting out in coding, and getting my development environment set up on Windows is taking a good chunk of my time by itself unfortunately.

i have a same error... please rescue us

any luck with this?

someone has solved this problem, please help

How did you fix this problem... please help

Hi, it's a great guide! I got through all steps successfully.
However, when I tried to create a newapp, I got the following error.

error: chmod on /mnt/c/code/.git/config.lock failed: Operation not permitted
fatal: could not set 'core.repositoryformatversion' to '0'

I already made sure the folder is writable.

Thank you!

Did you solve this issue? if yes, what's the solution?

https://evandontje.com/2020/03/03/setting-up-git-running-under-WSL/
This worked for me, just make sure you cd out of /mnt/c/ before you run it

It's no longer possible to install bash using the bash command, now you need to install a linux distribution via the Microsoft App Store

https://www.howtogeek.com/249966/how-to-install-and-use-the-linux-bash-shell-on-windows-10/

details in the link above

I was having the same problem as Alison Y. The solution for me was to remake the code directory using the "-p" option.

I believe curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - should be changed for curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -

on WSL 1 (and WSL 2), rake running inside linux cant connect to postgresql running in windows through a unix domain socket. Instead you will need to connect using regular network over TCP/IP.

first, you need to determine your windows ip address. You can find this by looking in windows network settings; or by running ipconfig in powershell. In your linux, ipconfig.exe | grep IPv4 | cut -d: -f2 should work as well.

next in your rails cofig/database.yaml, uncomment the #host 127.0.0.1 line and change it to your ip address. Also, update the username, password, and port as necessary. (did you create the user in postgresql?)

for example:

...
development:
  <<: *default
  database: myapp_development

  # The specified database role being used to connect to postgres.
  # To create additional roles in postgres see `$ createuser --help`.
  # When left blank, postgres will use the default role. This is
  # the same name as the operating system user that initialized the database.
  username: myapp

  # The password associated with the postgres role (username).
  password: <%= ENV['MYAPP_DATABASE_PASSWORD'] %>

  # Connect on a TCP socket. Omitted by default since the client uses a
  # domain socket that doesn't need configuration. Windows does not have
  # domain sockets, so uncomment these lines.
  #host: 127.0.0.1
  host: 10.0.0.99

  # The TCP port the server listens on. Defaults to 5432.
  # If your server runs on a different port number, change accordingly.
  port: 5432
...

finally, you have to modify postgresql's pg_hba.conf file (located in postgresql's data folder) to give permission for the incoming network connection.

example:

...
# From rails myapp in local Ubuntu WSL distro
host    myapp_development myapp         10.0.0.99/32            md5
...

current documentation for WSL 2 says WSL 2 will also work using the ip address of the host. So this method should continue to work for WSL 2. docs: Accessing Windows Applications From Linux

Thank you for this! One more item to note for WSL2 - check your Windows Firewall and allow port 5432.

@brandon-olin I have the same error. Did you manage to solve it?

I installed all with no problem, but when I go to open my site show me this error:
![https://prnt.sc/s2201n]
![https://prnt.sc/s220ev]
![https://prnt.sc/s220k5]

how to solve it?

I've tried this 5 times and they all fail in a different spot, first being the MySQL install, then the GitHub SSH Key, then 3 other random failures, any way to completely strip it from my system and start fresh?

i cant do rake db:create, everytime i get this error

Created database 'guardcenter_development'
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
Couldn't create 'GuardCenter_test' database. Please check your configuration.
rake aborted!
PG::ConnectionBad: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

Make sure in your database.yml, you have database, username, password, host, and port entered properly for both guardcenter_development and GuardCenter_test, for example

development:
<<: *default
database: guardcenter_development
username: guardcenter
password: pass
host: localhost
port: 5432

test:
<<: *default
database: guardcenter_test
username: guardcenter
password: pass
host: localhost
port: 5432

I had the same issue. What I did is:

  • Uninstall Postgresql
  • Install it again by following the instructions here: https://docs.microsoft.com/en-us/windows/wsl/tutorials/wsl-database#install-postgresql
  • open a terminal and run "psql -U postgres"
  • create a new user by running "CREATE USER user_name WITH PASSWORD 'your_password';"
  • check if the user is created "\du"
  • add some roles "ALTER ROLE user_name CREATEROLE CREATEDB"
  • update your database.yml file with your new user credentials.
  • run "rake db:create"
  • your DB should be created.

IF YOU ARE HAVING TROUBLES WITH THE INICIALIZATION OF THE PROJECT, PLEASE FOLLOW THIS STEPS

The steps that I only had to change to work for me was:

  • In the sixth step, add the semmicolon at the end of the sentence
  • I did'nt had to update the database.yml, because when I create the user of the fifth step, I used the user that I put when was doing the postgres installation
  • Before of run the "rake: db:create", run your postgres in another tab using "sudo service postgresql start"

Then, run the rake and the rails server and be happy again!

Hi,

I got all the way through this so thanks for the walk through!

i ran
rails new sample
and got the following error
create
create README.md
create Rakefile
create .ruby-version
create config.ru
create .gitignore
create .gitattributes
create Gemfile
run git init from "."
error: chmod on /mnt/c/Users/chun/Desktop/rails_project/side_project/sample/.git/config.lock failed: Operation not permitted
fatal: could not set 'core.filemode' to 'false'
create package.json
create app
create app/assets/config/manifest.js
create app/assets/stylesheets/application.css
create app/channels/application_cable/channel.rb
create app/channels/application_cable/connection.rb
create app/controllers/application_controller.rb
create app/helpers/application_helper.rb
create app/javascript/channels/consumer.js
create app/javascript/channels/index.js
create app/javascript/packs/application.js
create app/jobs/application_job.rb
create app/mailers/application_mailer.rb
create app/models/application_record.rb
create app/views/layouts/application.html.erb
create app/views/layouts/mailer.html.erb
create app/views/layouts/mailer.text.erb
create app/assets/images
create app/assets/images/.keep
create app/controllers/concerns/.keep
create app/models/concerns/.keep
create bin
create bin/rails
create bin/rake
create bin/setup
create bin/spring
create bin/yarn
/home/chun/.rbenv/versions/3.0.0/lib/ruby/3.0.0/fileutils.rb:1346:in chmod': Operation not permitted @ apply2files - /mnt/c/Users/chun/Desktop/rails_project/side_project/sample/bin (Errno::EPERM)
from /home/chun/.rbenv/versions/3.0.0/lib/ruby/3.0.0/fileutils.rb:1346:in
chmod'
from /home/chun/.rbenv/versions/3.0.0/lib/ruby/3.0.0/fileutils.rb:1038:in block (2 levels) in chmod_R'
from /home/chun/.rbenv/versions/3.0.0/lib/ruby/3.0.0/fileutils.rb:1493:in
preorder_traverse'
from /home/chun/.rbenv/versions/3.0.0/lib/ruby/3.0.0/fileutils.rb:1036:in block in chmod_R'
from /home/chun/.rbenv/versions/3.0.0/lib/ruby/3.0.0/fileutils.rb:1035:in
each'
from /home/chun/.rbenv/versions/3.0.0/lib/ruby/3.0.0/fileutils.rb:1035:in chmod_R'
from /home/chun/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/thor-1.0.1/lib/thor/actions/file_manipulation.rb:154:in
chmod'
from /home/chun/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/railties-6.1.0/lib/rails/generators/rails/app/app_generator.rb:19:in chmod'
from /home/chun/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/railties-6.1.0/lib/rails/generators/rails/app/app_generator.rb:96:in
bin'
from /home/chun/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/railties-6.1.0/lib/rails/generators/app_base.rb:164:in public_send'
from /home/chun/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/railties-6.1.0/lib/rails/generators/app_base.rb:164:in
build'
from /home/chun/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/railties-6.1.0/lib/rails/generators/rails/app/app_generator.rb:354:in create_bin_files'
from /home/chun/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/thor-1.0.1/lib/thor/command.rb:27:in
run'
from /home/chun/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/thor-1.0.1/lib/thor/invocation.rb:127:in invoke_command'
from /home/chun/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/thor-1.0.1/lib/thor/invocation.rb:134:in
block in invoke_all'
from /home/chun/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/thor-1.0.1/lib/thor/invocation.rb:134:in each'
from /home/chun/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/thor-1.0.1/lib/thor/invocation.rb:134:in
map'
from /home/chun/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/thor-1.0.1/lib/thor/invocation.rb:134:in invoke_all'
from /home/chun/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/thor-1.0.1/lib/thor/group.rb:232:in
dispatch'
from /home/chun/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/thor-1.0.1/lib/thor/base.rb:485:in start'
from /home/chun/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/railties-6.1.0/lib/rails/commands/application/application_command.rb:26:in
perform'
from /home/chun/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/thor-1.0.1/lib/thor/command.rb:27:in run'
from /home/chun/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/thor-1.0.1/lib/thor/invocation.rb:127:in
invoke_command'
from /home/chun/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/thor-1.0.1/lib/thor.rb:392:in dispatch'
from /home/chun/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/railties-6.1.0/lib/rails/command/base.rb:69:in
perform'
from /home/chun/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/railties-6.1.0/lib/rails/command.rb:50:in invoke'
from /home/chun/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/railties-6.1.0/lib/rails/cli.rb:18:in
'
from internal:/home/chun/.rbenv/versions/3.0.0/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb:85:in require'
from <internal:/home/chun/.rbenv/versions/3.0.0/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in
require'
from /home/chun/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/railties-6.1.0/exe/rails:10:in <top (required)>'
from /home/chun/.rbenv/versions/3.0.0/bin/rails:23:in
load'
from /home/chun/.rbenv/versions/3.0.0/bin/rails:23:in `

'

Anyone have any idea what went wrong?

I just had the same issue. This helped me. https://superuser.com/a/1343737

I also have same issue. can you explain it a bit.
Also I followed the link but didn't get the results.

shutdown ubuntu and remove myapp folder in C:\
after restarting ubuntu (recommend to begin with administration permission), type this below two lines
sudo umount /mnt/c
sudo mount -t drvfs C: /mnt/c -o metadata
then try below line again
rails new myapp -d postgresql
It was helpful for me.

your solution worked to me too

error: chmod on /mnt/c/code/myapp/.git/config.lock failed: Operation not permitted

If you want to use Postgres

Note that this will expect a postgres user with the same username

as your app, you may need to edit config/database.yml to match the

user you created earlier

SOLUTION:
close all shell windows
open a new windows powershell
wsl --shutdown
exit
Open ubuntu
rails new myapp -d postgresql

Just make sure windows is updated and WSL2 is installed

You are a legend! this SOLUTION helped me most of call...
SOLUTION:
close all shell windows
open a new windows powershell
wsl --shutdown
exit
Open ubuntu
rails new myapp -d postgresql

My 'rails new myapp...' was not generating the project I expected. For instance there was no config/database.yml This solution did the trick. Thanks.

could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

Thanks. My app is working. I had to follow ROD's solution above plus install a newer version of yarn so that I could install webpacker.

sudo apt-get update
sudo apt-get install yarn
rails webpacker:install

You'll also want to add host/port/username/password to default in the database.yml before running rake

why is this ? : helloworld@DESKTOP-BT0GAQJ:/mnt/c/code$ rails new myapp -d postgresql

  create
  create  README.md
  create  Rakefile
  create  .ruby-version
  create  config.ru
  create  .gitignore
  create  Gemfile
     run  git init from "."

error: chmod on /mnt/c/code/myapp/.git/config.lock failed: Operation not permitted
fatal: could not set 'core.filemode' to 'false'
create package.json
create app
create app/assets/config/manifest.js
create app/assets/stylesheets/application.css
create app/channels/application_cable/channel.rb
create app/channels/application_cable/connection.rb
create app/controllers/application_controller.rb
create app/helpers/application_helper.rb
create app/javascript/channels/consumer.js
create app/javascript/channels/index.js
create app/javascript/packs/application.js
create app/jobs/application_job.rb
create app/mailers/application_mailer.rb
create app/models/application_record.rb
create app/views/layouts/application.html.erb
create app/views/layouts/mailer.html.erb
create app/views/layouts/mailer.text.erb
create app/assets/images
create app/assets/images/.keep
create app/controllers/concerns/.keep
create app/models/concerns/.keep
create bin
create bin/rails
create bin/rake
create bin/setup
create bin/yarn
/home/helloworld/.rbenv/versions/3.0.1/lib/ruby/3.0.0/fileutils.rb:1346:in chmod': Operation not permitted @ apply2files - /mnt/c/code/myapp/bin (Errno::EPERM)
from /home/helloworld/.rbenv/versions/3.0.1/lib/ruby/3.0.0/fileutils.rb:1346:in
chmod'
from /home/helloworld/.rbenv/versions/3.0.1/lib/ruby/3.0.0/fileutils.rb:1038:in block (2 levels) in chmod_R'
from /home/helloworld/.rbenv/versions/3.0.1/lib/ruby/3.0.0/fileutils.rb:1493:in
preorder_traverse'
from /home/helloworld/.rbenv/versions/3.0.1/lib/ruby/3.0.0/fileutils.rb:1036:in block in chmod_R'
from /home/helloworld/.rbenv/versions/3.0.1/lib/ruby/3.0.0/fileutils.rb:1035:in
each'
from /home/helloworld/.rbenv/versions/3.0.1/lib/ruby/3.0.0/fileutils.rb:1035:in chmod_R'
from /home/helloworld/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/thor-1.1.0/lib/thor/actions/file_manipulation.rb:154:in
chmod'
from /home/helloworld/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/railties-6.0.3/lib/rails/generators/rails/app/app_generator.rb:19:in chmod'
from /home/helloworld/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/railties-6.0.3/lib/rails/generators/rails/app/app_generator.rb:92:in
bin'
from /home/helloworld/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/railties-6.0.3/lib/rails/generators/app_base.rb:155:in build'
from /home/helloworld/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/railties-6.0.3/lib/rails/generators/rails/app/app_generator.rb:303:in
create_bin_files'
from /home/helloworld/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/thor-1.1.0/lib/thor/command.rb:27:in run'
from /home/helloworld/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/thor-1.1.0/lib/thor/invocation.rb:127:in
invoke_command'
from /home/helloworld/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/thor-1.1.0/lib/thor/invocation.rb:134:in block in invoke_all'
from /home/helloworld/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/thor-1.1.0/lib/thor/invocation.rb:134:in
each'
from /home/helloworld/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/thor-1.1.0/lib/thor/invocation.rb:134:in map'
from /home/helloworld/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/thor-1.1.0/lib/thor/invocation.rb:134:in
invoke_all'
from /home/helloworld/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/thor-1.1.0/lib/thor/group.rb:232:in dispatch'
from /home/helloworld/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/thor-1.1.0/lib/thor/base.rb:485:in
start'
from /home/helloworld/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/railties-6.0.3/lib/rails/commands/application/application_command.rb:26:in perform'
from /home/helloworld/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/thor-1.1.0/lib/thor/command.rb:27:in
run'
from /home/helloworld/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/thor-1.1.0/lib/thor/invocation.rb:127:in invoke_command'
from /home/helloworld/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/thor-1.1.0/lib/thor.rb:392:in
dispatch'
from /home/helloworld/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/railties-6.0.3/lib/rails/command/base.rb:69:in perform'
from /home/helloworld/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/railties-6.0.3/lib/rails/command.rb:46:in
invoke'
from /home/helloworld/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/railties-6.0.3/lib/rails/cli.rb:18:in <top (required)>'
from <internal:/home/helloworld/.rbenv/versions/3.0.1/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in
require'
from internal:/home/helloworld/.rbenv/versions/3.0.1/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb:85:in require'
from /home/helloworld/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/railties-6.0.3/exe/rails:10:in
'
from /home/helloworld/.rbenv/versions/3.0.1/bin/rails:23:in load'
from /home/helloworld/.rbenv/versions/3.0.1/bin/rails:23:in

'
helloworld@DESKTOP-BT0GAQJ:/mnt/c/code$

Thank you so much. I'm super excited to find out this Windows 10 discussion thread.

For anyone having problems with WSL and Postgres when running rake db:create, try adding host: 127.0.0.1 in config/database.yml to default: &default as you're using TCP, not a Unix socket.

Hi
after rake db:create I got and error
rake aborted!
LoadError: cannot load such file -- /mnt/c/myapp/config/application
/mnt/c/myapp/rakefile:4:in require_relative'
/mnt/c/myapp/rakefile:4:in
'
(See full trace by running task with --trace)

Your rakefile should be getting application.rb, not application. Make sure your rakefile is actually trying to get application.rb and not application.

thank you for this article!... I am new to rails but this article made it so much simple for me, thank you!

Small newbie error occurred for me. I got "git@github.com: Permission denied (publickey)." There were two problems. There was a prompt that had asked me for a name for the file for the generated key. I didn't know that this had to be a particular name, so I made up my own name. Also, the two files created were placed in the wrong folder. So I moved the files that I renamed to id_rsa.pub and id_rsa from my home directory to the folder /.ssh and then tried to connect again. This time I was successful.

Hello, I was following the instruction here. When I created a new app:

rails new myapp -d postgresql

It created the "myapp" application without the config directory. In addition, when I installed the dependencies for Ruby, these two commands:

libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev
libcurl4-openssl-dev software-properties-common libffi-dev

are not found (according to the terminal. All I did was "copy and paste" these commands, so there wasn't any potential typos there)

Because I later installed PostgreSQL, so hopefully, the command above for sqlite3 is not that necessary but the one for openSSL remains a concern.

Also, when I ran: rake db:create

rake aborted!
LoadError: cannot load such file -- /mnt/c/myapp/config/application
/mnt/c/myapp/rakefile:4:in require_relative'
/mnt/c/myapp/rakefile:4:in
'

Someone on this board suggests that "application" be changed to "application.rb" in Rakefile, I tried that but it didn't help. Also, my application was created with the config directory missing :-)

Sorry for multiple problems. Any help will be much appreciated. Thanks!

Your issues probably stem from the fact you don't have those dependencies. What's your Ubuntu version? Have you tried sudo apt update and sudo apt install libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev
libcurl4-openssl-dev software-properties-common libffi-dev
?

Elijah, I appreciate your prompt assistance! I was able to run the above two commands ... However, when creating a new rails app:

rails new myapp -d postgresql

It seemed to have a file and directory permission issue that prevents the rest of the myapp directory from being created (please see below):

from ~/.rbenv/versions/3.0.2/lib/ruby/3.0.0/fileutils.rb:1346:in chmod': Operation not permitted @ apply2files - /mnt/c/code/myapp/bin (Errno::EPERM)
from ~/.rbenv/versions/3.0.2/lib/ruby/3.0.0/fileutils.rb:1346:in
chmod'
from ~/.rbenv/versions/3.0.2/lib/ruby/3.0.0/fileutils.rb:1038:in block (2 levels) in chmod_R'
from ~/.rbenv/versions/3.0.2/lib/ruby/3.0.0/fileutils.rb:1493:in
preorder_traverse'
from ~/.rbenv/versions/3.0.2/lib/ruby/3.0.0/fileutils.rb:1036:in block in chmod_R'
from ~/.rbenv/versions/3.0.2/lib/ruby/3.0.0/fileutils.rb:1035:in
each'
from ~/.rbenv/versions/3.0.2/lib/ruby/3.0.0/fileutils.rb:1035:in chmod_R'
from ~/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/thor-1.1.0/lib/thor/actions/file_manipulation.rb:154:in
chmod'
...

I did set: chmod 700 fileutils.rb
I even set: chmod 777 ruby (on the ruby directory) but neither helped.

Any idea ? Thanks!

I assume you're using WSL, which can cause a bug where files can be owned by root instead of your user. Try restarting your computer and see if WSL fixes itself, or check who actually owns the folder with ls -al. sudo chown -R your_wsl_user myapp should work.

Finally, check if the attributes of myapp aren't immutable. Change them if they are (chattr -R -ia myapp).

Elijah, you are the man! Indeed, restarting my computer made a big difference. I was able to create a new rails app with everything in it. The problem I'm facing right now is that when I ran

rake db:create

FATAL: password authentication failed for user "xyz"
Couldn't create 'myapp_development' database. Please check your configuration.

rake aborted!

I don't recall I was asked to set a password during the installation of PostgreSQL, so in the database.yml, I specified the same username and password as those I used for creating the Window sub-system for Linux. Long story short, I have spent a good amount of time searching on Google and have tried various methods but none have worked so far. I'm almost there. A few questions for you:

  • How do I set a new password for the existing username (assuming it recognizes the existing username) in PostgreSQL ?

  • How do I set a new username and a new password in PostgreSQL ?

  • Should I (not) store the password in plain text in the database.yml or encript it in someway ?

Many thanks for your kind assistance so far !

I got it. My Ruby on Rails app is up and running now. Thanks again!

Glad to know you got it working! I know you asked about how to secure your password in database.yml. Passwords must be provided as-is in that file, but you could use environment variables. You can define your password in .env as export POSTGRES_UPASSWORD='password' and then refer to it with <%= ENV['POSTGRES_UPASSWORD'] %>. The problem with this approach is that you're just passing off your password to .env and really it only works if you're working with other people. Malicious code could still steal your environment variables. If you're willing to set up a server, you could set up another server for PostgreSQL and secure it, only allowing your IP address to connect. That way, even if they had the password, it's no good. Of course, then you need to keep your SSH keys secure.

The truth is that there's no good way to protect against an attack other than practicing good security on your machine.

Hello again

I would like to be able to run rails commands from within the Visual Studio Code built-in terminal. They work fine on WSL terminals but I prefer to run them from within the VS code terminal. So when I ran something like "rails console" in VS Code, it said "The term 'rails' is not recognized as the name of a cmdlet, function, script file, or operable program ..." Upon some research on Google, someone suggests that the path to the rails/bin directory be added as an environmental variable. This is actually not hard. The hard part is to figure out where in the world rails was installed on WSL :-), can't find it. I know that my WSL was installed in C:\Users\tommy\AppData\Local\Packages but can't find the rails directory in Packages. Any idea ? Thanks again !

The reason why is because in VS Code it by default uses either PWSH/Command Prompt for commands (I don't know, but for me it's PWSH). You need to change it to WSL by clicking the plus icon to the right of the tabs in the terminal window and add "WSL". If it doesn't appear, you may need to get the Remote Development extension and use it that way. Your Rails installation is managed through WSL so adding it as an environment variable wouldn't work.

Elijah, you are the man (again) ! It worked, thanks a lot !

You're welcome!

When running rake db:create

I get this error

could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
Couldn't create 'myapp_development' database. Please check your configuration.
rake aborted!
ActiveRecord::NoDatabaseError: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

Caused by:
PG::ConnectionBad: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

Tasks: TOP => db:create
(See full trace by running task with --trace)

How do i fix this?

Add host: 127.0.0.1 in config/database.yml to default: &default as you're using TCP, not a Unix socket.

Adding following lines to default: &default
host: 127.0.0.1
user:
password:
and then running rake db:create helped the database created

Good article thanks... without it, I would be stuck for a week. I wasted 5 hours trying to get windows, ruby, rails and intellij IDEA to play together and gave up. I hit a few snags on this mostly at the end due to different ubunutu and ubuntu LTS (whatever that is) being installed and also there was some wierd issue with WSL not enabling systemctl by default, wtf? oh well, I have a working server so thanks. Wish they would make and keep up to date a good yum/rpm and windows installers, standup time is important for any software, but still re-learning ruby so...

PLEASE KEEP ARTICLE UP TO DATE AND REVERSE COMPATIBLE OR WE WILL ALL BE STUCK, LOL, THANKS!

anyone got it working? if yes, maybe post your conf, im on win 11, all good till rake db:create PG::ConnectionBad: could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?
i modified the postgres conf to listen to wls ip, but im stuck here, reading a lot of copy paste articles, all sayin u need to start postgres service, but thats a nonsense if u use it in windows, anyway, im stuck here, any help is welcome.

Hi,
I'm new in this programming language, installed ruby on rails by completing every step shown up here. When I create a simple project it is working fine but when I create a project with tailwindcss it is throwing error like this:

  • /home/mirkomilboy/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/tailwindcss-rails-2.0.12-x86_64-linux/exe/x86_64-linux/tailwindcss -i /mnt/c/rubyonrails/test-app/app/assets/stylesheets/application.tailwind.css -o /mnt/c/rubyonrails/test-app/app/assets/builds/tailwind.css -c /mnt/c/rubyonrails/test-app/config/tailwind.config.js --minify /home/mirkomilboy/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/tailwindcss-rails-2.0.12-x86_64-linux/exe/x86_64-linux/tailwindcss: 1: ELF: not found

/home/mirkomilboy/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/tailwindcss-rails-2.0.12-x86_64-linux/exe/x86_64-linux/tailwindcss: 4: Syntax error: word unexpected (expecting ")")
rails aborted!

Command failed with exit 2: /home/mirkomilboy/.rbenv/versions/3.1.2/bin/ruby /home/mirkomilboy/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/tailwindcss-rails-2.0.12-x86_64-linux/lib/tasks/../../exe/tailwindcss -i '/mnt/c/rubyonrails/test-app/app/assets/stylesheets/application.tailwind.css' -o '/mnt/c/rubyonrails/test-app/app/assets/builds/tailwind.css' -c '/mnt/c/rubyonrails/test-app/config/tailwind.config.js' --minify

I've done some research but could not solve the issue. Can anyone help me with this? Thanks in advance!

hello guys please i need your help

zainab@DESKTOP-6EV5CHP:/mnt/c/myapp$ rake db:create
rake aborted!
LoadError: cannot load such file -- /mnt/c/myapp/config/application
/mnt/c/myapp/rakefile:4:in require_relative'
/mnt/c/myapp/rakefile:4:in
'
(See full trace by running task with --trace)
zainab@DESKTOP-6EV5CHP:/mnt/c/myapp$
zainab@DESKTOP-6EV5CHP:/mnt/c/myapp$ rails server
bin/rails:3:in require_relative': cannot load such file -- /mnt/c/myapp/config/boot (LoadError)
from bin/rails:3:in

'
zainab@DESKTOP-6EV5CHP:/mnt/c/myapp$ rake db:create
rake aborted!
LoadError: cannot load such file -- /mnt/c/myapp/config/application
/mnt/c/myapp/rakefile:4:in require_relative'
/mnt/c/myapp/rakefile:4:in
'
(See full trace by running task with --trace)
zainab@DESKTOP-6EV5CHP:/mnt/c/myapp$
this is the problem i am facing while trying to create a rake db

please can anyone help me
zainab@DESKTOP-6EV5CHP:/mnt/c$ rails new myapp -d postgresql
create
create README.md
create Rakefile
create .ruby-versionwill be installed:
create config.ru
create .gitignorealled, 0 to remove and 171 not upgraded.
create .gitattributeses.
create Gemfile 1001 kB of additional disk space will be used.
run git init from "."y
error: chmod on /mnt/c/myapp/.git/config.lock failed: Operation not permitted12.13-0ubuntu0.20.04.1 [118 kB]
fatal: could not set 'core.filemode' to 'false'dates/main amd64 libpq-dev amd64 12.13-0ubuntu0.20.04.1 [137 kB]
fatal: not a git repository (or any parent up to mount point /mnt)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
create app
create app/assets/config/manifest.js
create app/assets/stylesheets/application.css
create app/channels/application_cable/channel.rb
create app/channels/application_cable/connection.rb
create app/controllers/application_controller.rb
create app/helpers/application_helper.rb
create app/jobs/application_job.rb
create app/mailers/application_mailer.rb
create app/models/application_record.rb
create app/views/layouts/application.html.erb
create app/views/layouts/mailer.html.erb
create app/views/layouts/mailer.text.erb
create app/assets/images
create app/assets/images/.keep
create app/controllers/concerns/.keep
create app/models/concerns/.keep
create bin
create bin/rails
create bin/rake
create bin/setup
/home/zainab/.rbenv/versions/3.2.0/lib/ruby/3.2.0/fileutils.rb:2222:in chmod': Operation not permitted @ apply2files - /mnt/c/myapp/bin (Errno::EPERM)
from /home/zainab/.rbenv/versions/3.2.0/lib/ruby/3.2.0/fileutils.rb:2222:in
chmod'
from /home/zainab/.rbenv/versions/3.2.0/lib/ruby/3.2.0/fileutils.rb:1836:in block (2 levels) in chmod_R'
from /home/zainab/.rbenv/versions/3.2.0/lib/ruby/3.2.0/fileutils.rb:2369:in
preorder_traverse'
from /home/zainab/.rbenv/versions/3.2.0/lib/ruby/3.2.0/fileutils.rb:1834:in block in chmod_R'
from /home/zainab/.rbenv/versions/3.2.0/lib/ruby/3.2.0/fileutils.rb:1833:in
each'
from /home/zainab/.rbenv/versions/3.2.0/lib/ruby/3.2.0/fileutils.rb:1833:in chmod_R'
from /home/zainab/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/thor-1.2.1/lib/thor/actions/file_manipulation.rb:154:in
chmod'
from /home/zainab/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/railties-7.0.4/lib/rails/generators/rails/app/app_generator.rb:19:in chmod'
from /home/zainab/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/railties-7.0.4/lib/rails/generators/rails/app/app_generator.rb:95:in
bin'
from /home/zainab/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/railties-7.0.4/lib/rails/generators/app_base.rb:134:in public_send'
from /home/zainab/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/railties-7.0.4/lib/rails/generators/app_base.rb:134:in
build'
from /home/zainab/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/railties-7.0.4/lib/rails/generators/rails/app/app_generator.rb:336:in create_bin_files'
from /home/zainab/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/thor-1.2.1/lib/thor/command.rb:27:in
run'
from /home/zainab/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in invoke_command'
from /home/zainab/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/thor-1.2.1/lib/thor/invocation.rb:134:in
block in invoke_all'
from /home/zainab/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/thor-1.2.1/lib/thor/invocation.rb:134:in each'
from /home/zainab/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/thor-1.2.1/lib/thor/invocation.rb:134:in
map'
from /home/zainab/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/thor-1.2.1/lib/thor/invocation.rb:134:in invoke_all'
from /home/zainab/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/thor-1.2.1/lib/thor/group.rb:232:in
dispatch'
from /home/zainab/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/thor-1.2.1/lib/thor/base.rb:485:in start'
from /home/zainab/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/railties-7.0.4/lib/rails/commands/application/application_command.rb:26:in
perform'
from /home/zainab/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/thor-1.2.1/lib/thor/command.rb:27:in run'
from /home/zainab/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in
invoke_command'
from /home/zainab/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/thor-1.2.1/lib/thor.rb:392:in dispatch'
from /home/zainab/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/railties-7.0.4/lib/rails/command/base.rb:87:in
perform'
from /home/zainab/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/railties-7.0.4/lib/rails/command.rb:48:in invoke'
from /home/zainab/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/railties-7.0.4/lib/rails/cli.rb:18:in
'
from internal:/home/zainab/.rbenv/versions/3.2.0/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb:85:in require'
from <internal:/home/zainab/.rbenv/versions/3.2.0/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:85:in
require'
from /home/zainab/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/railties-7.0.4/exe/rails:10:in <top (required)>'
from /home/zainab/.rbenv/versions/3.2.0/bin/rails:25:in
load'
from /home/zainab/.rbenv/versions/3.2.0/bin/rails:25:in <main>'
zainab@DESKTOP-6EV5CHP:/mnt/c$ cd myapp
zainab@DESKTOP-6EV5CHP:/mnt/c/myapp$ rake db:create
rake aborted!
LoadError: cannot load such file -- /mnt/c/myapp/config/application
/mnt/c/myapp/rakefile:4:in
require_relative'
/mnt/c/myapp/rakefile:4:in <top (required)>'
(See full trace by running task with --trace)
zainab@DESKTOP-6EV5CHP:/mnt/c/myapp$
zainab@DESKTOP-6EV5CHP:/mnt/c/myapp$ rails server
bin/rails:3:in
require_relative': cannot load such file -- /mnt/c/myapp/config/boot (LoadError)
from bin/rails:3:in <main>'
zainab@DESKTOP-6EV5CHP:/mnt/c/myapp$ rake db:create
rake aborted!
LoadError: cannot load such file -- /mnt/c/myapp/config/application
/mnt/c/myapp/rakefile:4:in
require_relative'
/mnt/c/myapp/rakefile:4:in `'
(See full trace by running task with --trace)
zainab@DESKTOP-6EV5CHP:/mnt/c/myapp$ rails new myapp -d postgresql

I’ve got identical issue following from that guide on Win10 WSL.

And i found this issue may be solved with Chmod/Chown WSL Improvements
https://devblogs.microsoft.com/commandline/chmod-chown-wsl-improvements/ 32

Use
sudo umount /mnt/c sudo mount -t drvfs C: /mnt/c -o metadata
to change /mnt/c setting and it works for me

*You must delete files from incomplete rails new command first

hi codrin thanks for your reply but i don't seem to understand please can you elaborate it a bit

please i have done everything this is what i have againzainab@DESKTOP-6EV5CHP:/mnt/c/Windows/system32/myapp$ rake db:create
We could not find your database: postgres. Which can be found in the database configuration file located at config/database.yml.

To resolve this issue:

  • Did you create the database for this app, or delete it? You may need to create your database.
  • Has the database name changed? Check your database.yml config has the correct database name.

To create your database, run:

    bin/rails db:create

Couldn't create 'myapp_development' database. Please check your configuration.
rake aborted!
ActiveRecord::NoDatabaseError: We could not find your database: postgres. Which can be found in the database configuration file located at config/database.yml.

To resolve this issue:

  • Did you create the database for this app, or delete it? You may need to create your database.
  • Has the database name changed? Check your database.yml config has the correct database name.

To create your database, run:

    bin/rails db:create

Caused by:
PG::ConnectionBad: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

Tasks: TOP => db:create
(See full trace by running task with --trace)

Hi Zainab, first in file explorer go to C:/ and delete myapp folder.
Then open terminal or cmd what whever you use for WSL and paste this command:
sudo umount /mnt/c sudo mount -t drvfs C: /mnt/c -o metadata
After try again:
rails new myapp -d postgresql
It should work

Did the:
rails new myapp -d postgresql command worked?

yes it did

thank you very much for your reply but this is what i have
zainab@DESKTOP-6EV5CHP:/mnt/c/myapp$ rake db:create
We could not find your database: postgres. Which can be found in the database configuration file located at config/database.yml.

To resolve this issue:

  • Did you create the database for this app, or delete it? You may need to create your database.
  • Has the database name changed? Check your database.yml config has the correct database name.

To create your database, run:

    bin/rails db:create

Couldn't create 'myapp_development' database. Please check your configuration.
rake aborted!
ActiveRecord::NoDatabaseError: We could not find your database: postgres. Which can be found in the database configuration file located at config/database.yml.

To resolve this issue:

  • Did you create the database for this app, or delete it? You may need to create your database.
  • Has the database name changed? Check your database.yml config has the correct database name.

To create your database, run:

    bin/rails db:create

Caused by:
PG::ConnectionBad: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

Tasks: TOP => db:create
(See full trace by running task with --trace)
zainab@DESKTOP-6EV5CHP:/mnt/c/myapp$
zainab@DESKTOP-6EV5CHP:/mnt/c/myapp$ rails server
=> Booting Puma
=> Rails 7.0.4.2 application starting in development
=> Run bin/rails server --help for more startup options
Puma starting in single mode...

  • Puma version: 5.6.5 (ruby 3.2.0-p0) ("Birdie's Version")
  • Min threads: 5
  • Max threads: 5
  • Environment: development
  • PID: 138
  • Listening on http://127.0.0.1:3000
  • Listening on http://[::1]:3000 Use Ctrl-C to stop C- Gracefully stopping, waiting for requests to finish === puma shutdown: 2023-02-05 08:21:21 +0000 ===
  • Goodbye! Exiting zainab@DESKTOP-6EV5CHP:/mnt/c/myapp$

is there anything else i need to do

You need to add the database credentials
open your editor (eg, Atom, Visual Code ... ) in the myapp app folder, go to config/database.yml find this lines
default: &default
host: localhost #add this line
adapter: postgresql
encoding: unicode
username: postgres #add this line
password: "put your password from the Postgresql install" #add this line
and then do:
rails db:create
in your terminal

default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see Rails configuration guide
# https://guides.rubyonrails.org/configuring.html#database-pooling
is this what you are talking about
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

yes add the lines
host: localhost
username: postgres
`password: your password #here put your password from the Postgresql install

hello codrin i am really sorry for disturbing you and thank you very much for your help this is what i have again
zainab@DESKTOP-6EV5CHP:/mnt/c/myapp$ rake db:create
Rails couldn't infer whether you are using multiple databases from your database.yml and can't generate the tasks for the non-primary databases. If you'd like to use this feature, please simplify your ERB.
rake aborted!
Cannot load database configuration:
YAML syntax error occurred while parsing /mnt/c/myapp/config/database.yml. Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Error: (): mapping values are not allowed in this context at line 19 column 10

Caused by:
Psych::SyntaxError: (): mapping values are not allowed in this context at line 19 column 10

Tasks: TOP => db:create => db:load_config
(See full trace by running task with --trace)

is there anything i can do

Can you paste exactly what you added in the config/database.yml?

it should be exactly like this:
default: &default
host: localhost
adapter: postgresql
encoding: unicode
username: postgres
password: Password123

instead of Password123 put your password

this is everything from my database
PostgreSQL. Versions 9.3 and up are supported.

Install the pg driver:

gem install pg

On macOS with Homebrew:

gem install pg -- --with-pg-config=/usr/local/bin/pg_config

On macOS with MacPorts:

gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config

On Windows:

gem install pg

Choose the win32 build.

Install PostgreSQL and put its /bin directory on your path.

Configure Using Gemfile

gem "pg"

c

default: &default
host: localhost
adapter: postgresql
encoding: unicode
username: postgres
password: password

# For details on connection pooling, see Rails configuration guide
# https://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

development:
<<: *default
database: myapp_development

# The specified database role being used to connect to postgres.
# To create additional roles in postgres see $ createuser --help.
# When left blank, postgres will use the default role. This is
# the same name as the operating system user running Rails.
#username: myapp

# The password associated with the postgres role (username).
#password:

# Connect on a TCP socket. Omitted by default since the client uses a
# domain socket that doesn't need configuration. Windows does not have
# domain sockets, so uncomment these lines.
#host: localhost

# The TCP port the server listens on. Defaults to 5432.
# If your server runs on a different port number, change accordingly.
#port: 5432

# Schema search path. The server defaults to $user,public
#schema_search_path: myapp,sharedapp,public

# Minimum log levels, in increasing order:
# debug5, debug4, debug3, debug2, debug1,
# log, notice, warning, error, fatal, and panic
# Defaults to warning.
#min_messages: notice

Warning: The database defined as "test" will be erased and

re-generated from your development database when you run "rake".

Do not set this db to the same as development or production.

test:
<<: *default
database: myapp_test

As with config/credentials.yml, you never want to store sensitive information,

like your database password, in your source code. If your source code is

ever seen by anyone, they now have access to your database.

Instead, provide the password or a full connection URL as an environment

variable when you boot the app. For example:

DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"

If the connection URL is provided in the special DATABASE_URL environment

variable, Rails will automatically merge its configuration values on top of

the values provided in this file. Alternatively, you can specify a connection

URL environment variable explicitly:

production:

url: <%= ENV["MY_APP_DATABASE_URL"] %>

Read https://guides.rubyonrails.org/configuring.html#configuring-a-database

for a full overview on how database connection configuration can be specified.

production:
<<: *default
database: myapp_production
username: myapp
password: <%= ENV["MYAPP_DATABASE_PASSWORD"] %>

please help i have tried everything this is what i have
rake db:create
rake aborted!
ActiveRecord::DatabaseConfigurations::InvalidConfigurationError: '{ default => }' is not a valid configuration. Expected '' to be a URL string or a Hash.
/mnt/c/myapp/rakefile:6:in `'
(See full trace by running task with --trace)
edit please if someone reply my comment how do i know

Can you paste all the database.yml file here I will correct it for you

i have paste it

PostgreSQL. Versions 9.1 and up are supported.

Install the pg driver:

gem install pg

On OS X with Homebrew:

gem install pg -- --with-pg-config=/usr/local/bin/pg_config

On OS X with MacPorts:

gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config

On Windows:

gem install pg

Choose the win32 build.

Install PostgreSQL and put its /bin directory on your path.

Configure Using Gemfile

gem 'pg'

default: &default
host: localhost
adapter: postgresql
encoding: unicode
username: postgres
password:
# For details on connection pooling, see Rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

development:
<<: *default
database: myapp_development

# The specified database role being used to connect to postgres.
# To create additional roles in postgres see $ createuser --help.
# When left blank, postgres will use the default role. This is
# the same name as the operating system user that initialized the database.
#username: myapp

# The password associated with the postgres role (username).
#password:

# Connect on a TCP socket. Omitted by default since the client uses a
# domain socket that doesn't need configuration. Windows does not have
# domain sockets, so uncomment these lines.
#host: localhost

# The TCP port the server listens on. Defaults to 5432.
# If your server runs on a different port number, change accordingly.
#port: 5432

# Schema search path. The server defaults to $user,public
#schema_search_path: myapp,sharedapp,public

# Minimum log levels, in increasing order:
# debug5, debug4, debug3, debug2, debug1,
# log, notice, warning, error, fatal, and panic
# Defaults to warning.
#min_messages: notice

Warning: The database defined as "test" will be erased and

re-generated from your development database when you run "rake".

Do not set this db to the same as development or production.

test:
<<: *default
database: myapp_test

As with config/secrets.yml, you never want to store sensitive information,

like your database password, in your source code. If your source code is

ever seen by anyone, they now have access to your database.

Instead, provide the password as a unix environment variable when you boot

the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database

for a full rundown on how to provide these environment variables in a

production deployment.

On Heroku and other platform providers, you may have a full connection URL

available as an environment variable. For example:

DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"

You can use this database configuration with:

production:

url: <%= ENV['DATABASE_URL'] %>

production:
<<: *default
database: myapp_production
username: myapp
password: <%= ENV['APMANAGER_DATABASE_PASSWORD'] %>

just add your password

i have added my password unfortunately this is what i keep having

rake db:create
rake aborted!
ActiveRecord::DatabaseConfigurations::InvalidConfigurationError: '{ default => }' is not a valid configuration. Expected '' to be a URL string or a Hash.
/mnt/c/myapp/rakefile:6:in `'
(See full trace by running task with --trace)

is there anything i can do

Delete the my app folder and redo
rails new myapp -d postgresql
After just add the lines in config/database.yml
But don't modify anything else and respect the indentation
Last do
rails db:create

this is what i am having now thanks for your help so far
rake db:create
We could not find your database: postgres. Which can be found in the database configuration file located at config/database.yml.

To resolve this issue:

  • Did you create the database for this app, or delete it? You may need to create your database.
  • Has the database name changed? Check your database.yml config has the correct database name.

To create your database, run:

    bin/rails db:create

Couldn't create 'myapp_development' database. Please check your configuration.
rake aborted!
ActiveRecord::NoDatabaseError: We could not find your database: postgres. Which can be found in the database configuration file located at config/database.yml.

To resolve this issue:

  • Did you create the database for this app, or delete it? You may need to create your database.
  • Has the database name changed? Check your database.yml config has the correct database name.

To create your database, run:

    bin/rails db:create

hi codrin thank you very much for your extensive help the other day it has finally work

hello who can help me
rake db:create
rake aborted!
ActiveRecord::DatabaseConfigurations::InvalidConfigurationError: '{ default => }' is not a valid configuration. Expected '' to be a URL string or a Hash.
/mnt/c/myapp/rakefile:6:in `'
(See full trace by running task with --trace)

Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 88,834+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.