THIS BLOG POST HAS MOVED: new site
This post is now deprecated with the public launch of WSL2. I have a new post documenting how to do this same set up with WSL2. Check it out over here. NOTE: If you are not running Windows 10 2004 Build 19041 or higher, then you can continue with this post using WSL1.
As a robotics researcher, I spend a lot of my time developing in a Linux-on-metal environment. This is because my work revolves around ROS (the Robot Operating System) which requires Ubuntu in order to run. If you want an intro to ROS and the power of working with this highly-extensible software I’ll point you to the ROS website which has many good resources explaining the abilities of this system. Ubuntu in and of itself is not a bad platform, but growing up as a Windows guy I’ve come to love Microsoft’s platform and many of the features and native apps that follow from it (who doesn’t love native, highly supported gaming and a rich ecosystem of powerful professional grade apps?). Plus, no Linux distribution I’ve ever used has quite the polish of Microsoft’s offering.
Because of this, I’ve often wanted a way to develop within ROS on top of Windows. This can be accomplished by spinning up a VM within VirtualBox or VMWare and simply diving into a full Ubuntu desktop, but that takes up precious resources and also means dealing with all the miscellaneous issues with a full Linux install that I’m trying to avoid. Put simply, I wish for a lightweight ROS development environment which will allow me to quickly jump in and out of it without slowing down my Windows host. There are two ways to accomplish this: one way is to simply load up a Docker image based on Ubuntu with ROS pre-installed and away you go. However, Docker containers don’t have a great connection with either your network or your local files and thus aren’t tightly integrated with the Windows platform they are hosted by. The second way to accomplish this is by using WSL (Windows Subsystem for Linux) which is what we will do below.
NOTE: If you’d like to know how to set this up in Docker, I have a tutorial here.
WSL is simply an emulation of Linux on top of Windows. With WSL 1 this is not quite a VM but also not quite bare-bones and is kind of a mongrel of an OS. You can find a good overview of how it works here. However, it works very well (except for file system performance which we’ll get into a little later) and can handle our ROS needs with ease.
NOTE: As I am writing this WSL 2 is in the works which uses a super light-weight VM on Hyper-V in order to create a fully fledged Linux environment with (almost) all the power of bare-bones Linux. I actually use WSL 2 for my development systems, but you have to run a Windows Insider version for that to work right now. I’ll write an updated post when WSL 2 officially goes live in Spring 2020.
The first step of setting up this ROS development environment on Windows is simply to enable the WSL feature and then install your preferred Linux distribution. Microsoft has a tutorial here about how to do it, but for the sake of continuity I’ll also put it in this walk-through.
To enable WSL, open up PowerShell as Administrator and run this command:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
This will only take a second or two to run (it’s really just flipping a switch internally on Windows) and then you’ll need to reboot your machine. During the reboot process you’ll see that it’s installing new features (that’s our WSL stuff!) and then you’ll be good to go.
Now you can head over to the Microsoft Store app and search for “linux”.
This will give you a bunch of options including Kali, Ubuntu, Debian, and others. For ROS we need Ubuntu installed and, since I spend most of my time on ROS Kinetic, I will choose Ubuntu 16.04 LTS. At the time of writing the store lists, Ubuntu, Ubuntu 16.04 LTS, and Ubuntu 18.04 LTS. If you’d like, you can install Ubuntu 18.04 LTS and then later on install ROS Melodic, but I will proceed in this walk-through assuming 16.04/Kinetic.
NOTE: Keep in mind that Ubuntu and ROS versions are paired with each other: 16.04/Kinetic and 18.04/Melodic. They don’t work interchangeably.
All that being said, simply click on your Ubuntu version of choice and then click install. This will take a bit depending on your internet speeds since the distribution is fairly large. Once it’s done though you’ll have a new app with the Ubuntu logo on it and the name Ubuntu 16/18.04 (depending on which one you chose).
Now we can launch that app and it will take a bit the first time as it needs to run through the initialization of the OS (remember that we are installing a complete operating system here). However, every other boot of WSL will only take a couple of seconds.
Once the initialization is complete you’ll need to create a username and password that you’ll use any other time you want to enter the WSL distribution.
Now you’re in! You have an (almost) fully-featured version of Ubuntu running within Windows with minimal resources being taken up and the ability to launch and kill it in a matter of seconds.
NOTE: Your WSL file system resides within your file explorer at
\\wsl$\Ubuntu-16.04 if you’re running Windows 10 19.03 or later).
WSL Extras (optional, but highly recommended)
These are a couple things that I always do in order to boost my WSL productivity. The first is to keep Windows Defender from constantly scanning WSL files (this boosts file system performance in WSL) and the second is to add an X-server to run GUI applications in Windows through WSL. We’ll tackle these below.
Add WSL to the Exclusions List
NOTE: This may only work for Windows 19.03 or later. Go ahead and try it though anyway and let me know how you get on if you’re running some earlier build.
First, open up the Windows Security app. Then click on “Virus & threat protection”.
Now under “Virus & threat protection settings” you’ll see a “Manage settings” option; click that.
Scroll way down to the bottom of the page and under “Exclusions” you’ll see an option for “Add or remove exclusions”; click that.
Now you’ll need to press the + next to “Add an exclusion” and then select “folder”. You should now be able to type in your WSL file system location (
\\wsl$\Ubuntu-16.04) and press enter.
Setup GUI forwarding
There are many X-server applications that will allow for GUI forwarding from WSL, but my favorite one is VcXsrv. Go here to download and install it.
Once you run the installer you may need to launch it from Start in order to set it up. You can simply press “next” a few times to accept all the defaults and then select “finish” to close it out. You should now see it’s icon down in your icon tray which means the server is running.
NOTE #1: right before you click “finish” you can select “Save configuration” so that you can simply double-click the config file to launch VcXsrv with all the defaults. This is a bit faster than clicking through every time.
NOTE #2: You may want to uncheck “Native opengl” and check “Disable access control”. On different systems I’ve had issues with the defaults here. If you do this, be sure to set the environment variable LIBGL_ALWAYS_INDIRECT=0 in your WSL terminal (you can just add
export LIBGL_ALWAYS_INDIRECT=0 to the end of your
.bashrc file). Your mileage may vary.
Once that’s set up, you can now open your Ubuntu app and run this command to setup the GUI forwarding by adding an export of the DISPLAY variable to your
.bashrc file. This way you’ll have this environment variable set with every new shell you open up:
echo 'export DISPLAY=:0' >> ~/.bashrc
Now source your edited
Now everything should be setup for GUI apps to be sent on to Windows for rendering and display. If you want to test the setup, you can install some basic apps within Ubuntu with the below package:
sudo apt update sudo apt install x11-apps
And then run:
To run one of the apps. Or you can install any of your favorite GUI apps or test it with ROS after we install that. Speaking of which…
Now to install ROS. The ROS team has a great installation guide over here at their website, but like before I’ll go ahead and show it here for completeness. Again note that the below commands are for Ubuntu 16.04/ROS Kinetic. If you chose to go with 18.04/Melodic you’ll need to alter these a tiny bit. Go here for more details.
First we need to add the ROS packages information to the sources list on our WSL system. To do this, open your Ubuntu app and run the below command:
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
Now we need to setup the keys for these package repositories:
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
NOTE: If you get some errors with the above command try substituting
Now we need to update the local list of available packages with these newly added ROS ones:
sudo apt update
Now we’re (finally) ready to install ROS. There’s a few options to choose from:
- desktop-full: This includes everything; rqt, rviz, simulators, navigation, perception, you name it.
- desktop: This has most of the above but lacks the simulators, navigators, and perception.
- ros-base: This is just the basics for getting up and running with ROS. No GUI tools and only what you need to package, build, and communicate over the ROS stack.
My recommendation is to go with
desktop-full unless you are super short on storage. It’ll take a bit more time for the initial install and take up more disk space, but you’re guaranteed to have most of the tools you need for anything you’d like to do. However, with all of these you can simply add more tools as you need them. Simply run
apt-cache search ros-kinetic to find which ones are available.
Once you’ve chosen the ROS installation you want to get, run the below command and substitute in your choice. I’ll do
sudo apt install ros-kinetic-desktop-full
This will take a long time to run. Remember when I said file system performance is bad on WSL? This is because it’s actually an emulated Linux file system on a Windows file system (this is changing in WSL 2). Don’t worry though, the actual performance of ROS when it’s running in WSL is pretty zippy.
Once it’s done with the install we need to initialize the dependency manager for ROS. Simply run these two commands:
sudo rosdep init rosdep update
ROS needs to be sourced each time you open a bash shell and so we can add it to the
~/.bashrc file using the below commands to add it and source it (you can source ROS every time but that defeats the point of making this a dedicated ROS development environment):
echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc source ~/.bashrc
One last thing to do. For most ROS development you’ll want to be able to build your own packages. So we need a couple more packages in order to make this work. So finally we run this last install command:
sudo apt install python-rosinstall python-rosinstall-generator python-wstool build-essential
And you’re done! Welcome to ROS on Windows!
Though this post is pretty long, none of this is actually too hard to setup and can be done in a matter of a few minutes (plus install times). It offers a fairly painless way to get started in ROS development on Windows for those who don’t want to run a VM or dual-boot their systems.
Once everything has been done above, you’re ready for some ROS development. Not everything will be supported in ROS with this setup (networking across devices may be a bit tricky though I’ve never tested it to see), but the basics are all there for most development. If you’re new to ROS, I’d suggest walking through all of the tutorials here to get a handle on things. At least go through the Beginner Level (you can just do one or the other of the C++ and Python ones) so that you have a good foundation to work off of.
I hope this is helpful to somebody and if you have any thoughts on how to improve don’t hesitate to let me know with a comment.
43 thoughts on “Setting up ROS in Windows through WSL”
I am trying to run rviz through this WSL, but it crashes at every instance. the error displayed is:
tihbohs@PC-25985:~/catkin_ws$ rosrun rviz rviz
[ INFO] [1575287225.352177900]: rviz version 1.12.17
[ INFO] [1575287225.352955900]: compiled against Qt version 5.5.1
[ INFO] [1575287225.354048500]: compiled against OGRE version 1.9.0 (Ghadamon)
QXcbConnection: XCB error: 149 (Unknown), sequence: 164, resource id: 0, major code: 143 (Unknown), minor code: 20
Segmentation fault (core dumped)
Hey Shobhit! Did you make sure to uncheck the “Native opengl” box in VcXsv? Sounds like that could be your problem.
Yes, i am sure. i did that. And at every run the rviz window pops up to open, but immediately crashes out.
LikeLiked by 1 person
The only way I’ve been able to reproduce that problem is by not unchecking “Native opengl” like I mentioned below. If that’s not the issue I’m not really sure what’s causing it. Are you using VcXsrv?
This happened to me too.
I used to force indirect rendering with: export LIBGL_ALWAYS_INDIRECT=1
Without this indirect rendering, rviz works for me.
LikeLiked by 1 person
Glad to hear it!
I had the same problem and i had to set LIBGL_ALWAYS_INDIRECT to 0 for rviz not to core dump (this is on VxXsrv). I guess with WSL “YMMV” really applies 😀
On a slightly separate note, i have been able to get rviz running on my windows installation of melodic to happily talk with melodic nodes running in WSL. It just worked out of the box which was a nice surprise and may be useful when interfacing with eg cameras and other devices. of course, ymmv…
LikeLiked by 1 person
Thanks for this! Just updated the post to mention setting that variable. On my install I didn’t have to mess with it, but I’ve heard from other people that it helps and it definitely doesn’t hurt to set the env variable manually.
Hey, I am having the same issues but I don’t know how to set LIBGL_ALWAYS_INDIRECT to 0. Could you please tell how you did? Thanks in advance
This is spelled out under Note #2 in Setup GUI Forwarding. You can add the below command
as a new line in your .bashrc file and then close and reopen your terminal.
I was getting error when trying to start rviz.
This did the trick for me:
Thank you very much, sir.
Pasting error code so others can reach:
[rviz-3] process has died [pid *****, exit code -11 …
The thing I was trying to run was: roslaunch rrbot_description rrbot_rviz.launch
I am getting the same error, how did you fix it?
Looks like he just set his environment variable. So just run this command or better yet, add it to your ~/.bashrc file.
How do you handle the networking // ROS MASTER URI ? Im stuck here (could be some basic networking but…) as the wsl ip is in the 175.x.x.x
LikeLiked by 1 person
Hey mick! I usually use ROS in WSL with only local nodes, but if you’re trying to connect nodes from another machine to ROS master in WSL you may try this route to open up the Windows firewall: https://newscrewdriver.com/2018/09/02/windows-10-wsl-can-run-ros-with-firewall-caveat/
Hey man, i made some good progress, networking is good in one way as in, i can see topics and sub to them, but for example setting up a goal in rviz doesnt work, i guess i’m on the right way, thanks for the fast answer !
This issue is a great resource. Thanks for sharing!
Glad to hear it!
Could you share more details on the networking you got working? I’m in a similar boat trying to get a Docker image on Windows (WSL2 backend) to communicate with a ROS master on another machine. Did the issue you commented below resolve all of your problems for a ROS install directly on WSL2? If so, which ports did you forward? ROS seems to want ports 1024-65000, which seems like too many to be using in that solution.
I have yet to resolve this issue, but in the meantime I created this package to allow you to “link” two roscores (which would bypass WSL2 issues).
Are you planning on updating for WSL2? I’ve been trying to decide if I should dual boot or go with a solution like this.
Neil, i tried dual boot and WSL and WSL wins hands down esp since you can run ROS on WSL and on windows and the nodes will happily talk to each other. Running in WSL you also get to use all the linux and windows tools at the same time, which is really nice. of course, WSL has its problems – eg USB access – but hopefully that will be sorted with WSL2. in reality USB is less of an issue as you can run ROS nodes accessing ports on windows and the rest on WSL.
At the end of the day, this is all about options and being able to use windows and linux at the same time is, for me, a winner.
I second this sentiment! I’ve had to dual boot for hardware access (USB, GPU, etc.), but do almost everything on WSL now. WSL2 will eventually add these abilities though. They announced at Build that this summer they’ll preview GPU access from WSL2.
Awesome thanks! Do either of you know much about the experimental Windows version of ROS?
I looked at it a year or so ago but ended up going the WSL route since it’s just the default version of ROS and thus has more support. If you try it let me know how it goes!
Yes I am!! I’m actually working on that post this week and will have it up by the weekend. Most things stay the same in terms of setup thankfully. Check back Saturday and it’ll be up!
The update for WSL2 is now live! Check it out here: https://jack-kawell.com/2020/06/12/ros-wsl2/
I am getting an error when launching xcalc. “Error: Can’t open display: :0”. How do I fix this? ROS installation was successful
Usually this means your DISPLAY variable isn’t set. Did you do this step?
echo ‘export DISPLAY=:0’ >> ~/.bashrc
Now source your edited .bashrc file:
I am not able to setup the keys. The “sudo apt-key adv…” seems to be started but not getting completed.
It says “Executing” but does not end
Please help in this regard
Did you try the alternative address? Sometimes these servers are down and you have to wait for them to come back up.
Thanks for the reply. I tried both the addresses. I am trying it for quite some days now. It still doesn’t work.
Would there be any other issue?
Thanks and Regards
The only thing I can think of is that your network is blocking it somehow. Maybe try a VPN (or get off a VPN) or disable a network firewall or ad-blocker?
Yes, even I feel the same. I am using Bitdefender Internet security and I think that its firewall is blocking it. I tried to include the wsl as an exception application in firewall settings but still not successful. 😦
Yeah I’d suggest just temporarily disabling Bitdefender while you install ROS.
Hi Jack, I am still getting: “Error: Can’t open display: :0” when I want to launch xcalc !
Would you please help me with this problem ?
I did run the following, as you stated above:
echo ‘export DISPLAY=:0’ >> ~/.bashrc
That’s odd. Are you using WSL2 or WSL1?
Hi Jack, Thanks for your reply.
I installed this wsl last year and now verified that is of version 2 by running:
wsl -l -v in the shell
It is Ubuntu-20.04
So I think it must be wsl2, isn’t it?
I appreciate your help 🙂
Yep! Networking is different in WSL2 so you’re best served by following my other tutorial on that one: https://jack-kawell.com/2020/06/12/ros-wsl2/