Skip to content

Instantly share code, notes, and snippets.

@kpheasey kpheasey/setup.md
Last active Jul 20, 2019

Embed
What would you like to do?
WSL, RVM & RubyMine; ubuntu on windows, bash on windows

Add inbound firewall rule for TCP 2222

  • Windows 10 has 2 new services, SSH Server Proxy and SSH Server Broker which will already be bound to port 22
  • Do not allow public connection on this rule, WSL is not proven safe

ConEmu

Add as cmd startup with bash.exe --login

Install the SSH server and some Rails essentials libraries in bash

sudo apt-get update && sudo apt-get upgrade -y
sudo apt-get install openssh-server libxml2 libxml2-dev libxslt1-dev libmysqlclient-dev nodejs libqt4-dev libqtwebkit-dev -y

Configure the SSH server

Ensure the following values are set in the configuration file.

  • ListenAddress 0.0.0.0
  • UsePrivilegeSeparation no
  • PasswordAuthentication yes
sudo nano /etc/ssh/sshd_config

Restart the SSH server

sudo service ssh restart

Note: you will need to start the SSH server if you close the bash window.

Install RVM

gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
\curl -sSL https://get.rvm.io | bash
source ~/.rvm/scripts/rvm
rvm install 2.3.1
rvm use 2.3.1 --default
gem install bundle

If you are getting errors when running bundle install, it may be because of bad permissions on the bundle cache directory. Set them to 0755.

find ~/.bundle/cache -type d -exec chmod 0755 {} +

Add new remote interpreter in RubyMine

  • Go to Settings > Languages & Frameworks > Ruby SDK and Gems
  • Click '+' and select New Remote...
  • Choose 'SSH Credentials'
  • Enter the following
    • Host: 127.0.0.1
    • Port: 2222
    • User name: [UBUNTU USER]
    • Auth type: Password
    • Ruby interpreter path: /home/[UBUNTU_USER]/.rvm/gems/ruby-2.3.1
@joshirashmics

This comment has been minimized.

Copy link

commented Sep 6, 2016

I have the lastest rubymine and apparantly rubymine doesn't work with wsl as of today.When starting the server, I get a Address already in use - bind(2) for 127.0.0.1:3001.. Changing the port doesn't make a differene. There are no other processes either in windows or wsl using the port. I have even tried restarting the machine.

@kneipp

This comment has been minimized.

Copy link

commented Nov 13, 2016

Tested with PHP and PHPStorm, works like a charm.
Thank you.

@pupeno

This comment has been minimized.

Copy link

commented Jan 6, 2017

If you are using gemsets, you might want to read the notes at the bottom here: https://www.jetbrains.com/help/ruby/2016.3/configuring-remote-ruby-interpreters.html

@joshirashmics

This comment has been minimized.

Copy link

commented Jan 22, 2017

Yes .. I always specified rvm gemset folder. And 2 for sure that has nothing to do with port already in use. It connects fine to ubuntu bash starts server and then throws error after that. Here is the log. If there is anyone who has had sucess connecting rubymine to bash please comment here. Till then I would continue to run my rails project in bash and edit project files in sublime in windows. That works faster. I would've only preferred rubymine over sublime for its vcs features.


/home/racjosh/.rvm/rubies/ruby-2.2.4/bin/ruby -e '$stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)' /mnt/c/Sites/testproject/bin/rails server -b 127.0.0.1 -p 3001 -e development
=> Booting WEBrick
=> Rails 4.2.6 application starting in development on http://127.0.0.1:3001
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2017-01-22 00:52:29] INFO  WEBrick 1.3.1
[2017-01-22 00:52:29] INFO  ruby 2.2.4 (2015-12-16) [x86_64-linux]
Exiting
/home/racjosh/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/socket.rb:206:in `bind': Address already in use - bind(2) for 127.0.0.1:3001 (Errno::EADDRINUSE)
	from /home/racjosh/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/socket.rb:206:in `listen'
	from /home/racjosh/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/socket.rb:461:in `block in tcp_server_sockets'
	from /home/racjosh/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/socket.rb:232:in `each'
	from /home/racjosh/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/socket.rb:232:in `foreach'
	from /home/racjosh/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/socket.rb:459:in `tcp_server_sockets'
	from /home/racjosh/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/webrick/utils.rb:70:in `create_listeners'
	from /home/racjosh/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/webrick/server.rb:133:in `listen'
	from /home/racjosh/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/webrick/server.rb:114:in `initialize'
	from /home/racjosh/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/webrick/httpserver.rb:45:in `initialize'
	from /home/racjosh/.rvm/gems/ruby-2.2.4/gems/rack-1.6.4/lib/rack/handler/webrick.rb:31:in `new'
	from /home/racjosh/.rvm/gems/ruby-2.2.4/gems/rack-1.6.4/lib/rack/handler/webrick.rb:31:in `run'
	from /home/racjosh/.rvm/gems/ruby-2.2.4/gems/rack-1.6.4/lib/rack/server.rb:286:in `start'
	from /home/racjosh/.rvm/gems/ruby-2.2.4/gems/railties-4.2.6/lib/rails/commands/server.rb:80:in `start'
	from /home/racjosh/.rvm/gems/ruby-2.2.4/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:80:in `block in server'
	from /home/racjosh/.rvm/gems/ruby-2.2.4/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:75:in `tap'
	from /home/racjosh/.rvm/gems/ruby-2.2.4/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:75:in `server'
	from /home/racjosh/.rvm/gems/ruby-2.2.4/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
	from /home/racjosh/.rvm/gems/ruby-2.2.4/gems/railties-4.2.6/lib/rails/commands.rb:17:in `<top (required)>'
	from /mnt/c/Sites/testproject/bin/rails:4:in `require'
@davisinfo

This comment has been minimized.

Copy link

commented Mar 1, 2017

I have the same problem, did you find a solution?

@davisinfo

This comment has been minimized.

Copy link

commented Mar 2, 2017

I have a feeling that RubyMine is setting a port forwarding on SSH that conflicts with rails server

@truongnmt

This comment has been minimized.

Copy link

commented Apr 23, 2017

when configure intepreter on RubyMine, I got java.net.ConnectException: Connection refused: connect
Also when trying to ssh on WSL: ssh: connect to host 127.0.0.1 port 22: Connection refused

@alexshenia

This comment has been minimized.

Copy link

commented May 3, 2017

when configure intepreter on RubyMine, I got java.net.ConnectException: Connection refused: connect
Also when trying to ssh on WSL: ssh: connect to host 127.0.0.1 port 22: Connection refused

same for me

@kpheasey could u help plz

@TechRsch

This comment has been minimized.

Copy link

commented May 15, 2017

Using RubyMine, I initially received the java.net.ConnectException error, but I had not set the SSH port. I changed that, restarted the SSH server, and it is now working fine.

@mausv

This comment has been minimized.

Copy link

commented Aug 23, 2017

For people getting "Connection refused", I got it working by running
sudo apt-get install openssh-server openssh-client
allowing inbound connections in the firewall (Windows-side) and finally setting the port to 2222 in the /etc/ssh/sshd_config file.

@lynxnathan

This comment has been minimized.

Copy link

commented Sep 19, 2017

I have the lastest rubymine and apparantly rubymine doesn't work with wsl as of today.When starting the server, I get a Address already in use - bind(2) for 127.0.0.1:3001.. Changing the port doesn't make a differene. There are no other processes either in windows or wsl using the port. I have even tried restarting the machine.

If anyone is still wondering, it seems rubymine is doing some shenanigans when you try to bind to 127.0.0.1 (loopback). One workaround is to use your physical network stack (ie. use your local network address. Ex: 192.168.0.x).

@ruanltbg

This comment has been minimized.

Copy link

commented Oct 23, 2017

Worked fine for me. Thanks

@vipl0ve

This comment has been minimized.

Copy link

commented Nov 3, 2017

I changed the Port from 2222 to 22 and it worked fine for me.

@dnlR

This comment has been minimized.

Copy link

commented Nov 27, 2017

@lynxnathan thanks! this is what worked for me.
Also note that in Rubyme inside run configurations you can set the path mappings: C:/ => /mnt/c/

@ckbkr

This comment has been minimized.

Copy link

commented Jan 7, 2018

Not a bad idea.

You forgot to mention the sshd_config location which is /etc/ssh/sshd_config

In your changes for the config you missed to mention the port

For rvm users using 'which ruby' produces the path to use in rubymine. Which is easier to copy-paste than filling in the blanks and crashing on the ruby version.

Still a pretty neat idea.

A neat addition for people who just want to use ruby and not ruby rails there is a local to remote folder mapping in the same configuartion location: Settings => Language.. => Ruby SDK... => the Icon right of the Plus used before

In case you have your ruby files on D:\myAwesomeRuby\ that'd be mapped on /mnt/d/myAwesomeRuby/ then you can run it in your IDE just fine.

@cec

This comment has been minimized.

Copy link

commented Jan 10, 2018

I get

Directory '/opt/.rubymine_helpers' doesn't exist on remote server

I don't get it: FW rule for 2222 is working, sshd_config changes too (I can ssh from git bash into my linux subsystem)

I gave the path to my RVM gemset...

Did anyone encounter a similar issue?

@Thejaswi05

This comment has been minimized.

Copy link

commented Jan 19, 2018

I got it working @mausv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.