Ask A Question

Notifications

You’re not receiving notifications from this thread.

Setup Windows 10 Discussion

Chris Oliver asked in General

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!

Reply

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

Reply

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

Reply

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

Reply

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

Reply

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 -

Reply

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

Reply

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

Reply

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

Reply

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?

Reply

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?

Reply

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"?

Reply

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

Reply

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.
Reply

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!

Reply

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?

Reply

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

Reply

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

Reply

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.

Reply

your solution worked to me too

Reply

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

Reply

Just make sure windows is updated and WSL2 is installed

Reply

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

Reply

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.

Reply

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"?

Reply

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

Reply

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$

Reply

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

Reply

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.

Reply

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)

Reply

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

Reply

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

Reply
Join the discussion
Create an account Log in

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

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

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