In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how to build a cross-platform development environment for Ubuntu on Windows10. I think it is very practical, so I share it with you. I hope you can get something after reading this article. Let's take a look at it.
A topic often debated by programmers is: is daily development better Windows or Linux? This leads to another question: is it better to choose MacBook or SurfaceBook?
The core reason for students who choose Linux system or mac notebook is that the Linux/Mac development and compilation tool chain is relatively perfect, and many environments or installation packages are included in the system. The programs written can be easily docked with online systems through development and testing, and the development and testing efficiency is relatively high, while students developing under Windows may need to consider the portability of development and testing code. Taking the author as an example, I have encountered some problems that java/python API does not support Windows, which brings a lot of trouble to daily development.
Before Windows10, in order to solve the cross-platform problem of Windows development environment, we often chose cygwin. The project itself is very mature, and the author has used it for many years. It can simulate a set of Linux-like environment under Windows, and it is not a big problem to deal with general development and testing problems. But its disadvantage is that the components and package managers are relatively weak, it is quite troublesome to maintain the environment in the future, and some of the underlying API simulations are not perfect, which is very scary for some scenarios such as system calls involving the underlying Linux. Fortunately, Microsoft began to build Ubuntu in Windows10 WSL in 2016, and then began to release various Linux systems in the form of UWP APP in Microsoft Store. In this way, students who need to build a cross-platform development environment can do multiple platform environments with one system, and there is one more reason to abandon Mac:)
Today, this article will explain in detail how to install Ubuntu under Windows10, build Linux development environment, some pits encountered and their solutions.
1. Install Ubuntu on Windows10
First update your Windows10 system to the latest, then open "developer mode", and finally type wsl (or Ubuntu, linux) in Microsoft Store and select install. After success, you can click start.
Note: some old tutorials online are installed in lxrun / install form from the command line, which is not recommended here, because this is the practice of the early version of WSL beta, and now the official version is more convenient and easy to manage directly in Microsoft Store in the form of UWP APP.
The final system is installed in the following directory:
% LOCALAPPDATA%\ Packages\ CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc
At the initial installation, the entire directory was about 600MB, and after I updated some packages and upgraded to 16.04, the size was 1G.
2. Enable sshd2.1 to set sshd
Reinstall openssh
Sudo apt-get remove openssh-serversudo apt-get install openssh-server
Modify the sshd settings to add the following configuration to / etc/ssh/sshd_config
AllowUsers your-usernamePasswordAuthentication yesPermitRootLogin yes
Restart sshd
Sudo service ssh-full-restart
It should not be unexpected to use the ssh client to link to Bash on windows.
2.2 problem 1:sshd startup error
# / etc/init.d/ssh restart
Sshd:.. / sysdeps/posix/getaddrinfo.c:2603: getaddrinfo: Assertion `IN6_IS_ADDR_V4MAPPED (sin6- > sin6_addr.s6_addr32) 'failed. Aborted (core dumped)
The reason is ipv6. Just modify the sshd_config configuration and add ListenAddress 0.0.0.0.
Sudo vi / etc/ssh/sshd_config
If you encounter the following error
Could not load host key: / etc/ssh/ssh_host_rsa_key
Please execute / usr/bin/ssh-keygen-A to regenerate host keys and restart sshd.
2.3 problem 2:ssh password error & & unable to listen on port
This problem is still quite complex to investigate, and there needs to be a more systematic investigation method and theory. The author has spent a lot of time here.
The phenomenon is that when the sshd service is up, both ps aux and top can be seen, but the password is always prompted when ssh is connected or there is no permission, but the password confirmation is correct, including the failure to create a new account. According to the troubleshooting idea of "recording a weird ssh mutual trust-free password login failure" in the previous article, it is found that the sshd service does not listen to the specified sshd port at all, and other ports have the same problem:
Nc-l 127.0.0.1 4444#on powershell:netstat-a-n-Q | findstr "4444"
That may be a system-level problem, and further analysis of the Windows system event discovery is a problem with the TDI filter:
We can find this driver file under windows/system32:
Restart the computer and test ok again:
3. Sshd starts up
Once the bash.exe process is turned off, the ssh cannot connect. There are three steps to solve this problem:
Add startup items to let bash.exe start at random
Start sshd using the command sudo service ssh start
Because the sudo service ssh start command requires a password to be entered, it cannot be automated, so visudo is required to avoid entering the password.
3.1 sort out the train of thought and then record some processes:
Use vbs to start a hidden window to open bash and run sudo service ssh start
Set ws=wscript.createobject ("wscript.shell") ws.run "C:WindowsSystem32bash.exe", 0ws.run "C:WindowsSystem32bash.exe-c 'sudo / usr/sbin/service ssh-- full-restart'", 0
Run sudo visudo and add the following configuration
Toor ALL = (root) NOPASSWD: / usr/sbin/service
Where toor is my user name.
Add the vbs file to the windows startup item and place the vbs file in the following directory.
% AppData%MicrosoftWindowsStart MenuProgramsStartup
Restart, the test will be able to connect to the ssh without an accident.
Another option is to use the scheduled task schedule that comes with windows to add tasks that boot up the Ubuntu ssh service:
Search for "Task Scheduler", operate-create basic tasks
Trigger: when the computer starts
Action: start the program
Program name: bash.exe
The parameter-c "sudo / usr/sbin/sshd-D" means to open bash and execute the sshd command to start the ssh service
Select the "Click finish Open property Page" button, click finish to open the property page
Select run with highest permissions on the property page to avoid errors.
Question 1: no sshd process after restart / boot
First of all, make sure that the code in each of the above three steps is correct, and then take a look at why the system log failed. What I encounter here is that sudo also needs a password, resulting in an error in the execution of the boot VB script. After careful study, the configuration file is as follows:
... # User privilege specificationroot ALL= (ALL:ALL) ALLmy-username ALL= (ALL) NOPASSWD: ALL#-> the line added by me# Members of the admin group may gain root privileges%admin ALL= (ALL) ALL# Allow members of group sudo to execute any command%sudo ALL= (ALL:ALL) ALL# See sudoers (5) for more information on "# include" directives:#includedir / etc/sudoers.d
You can see that my configuration is added in the middle, and there are several configurations behind it, causing my configuration to be overwritten later. The solution is to move my configuration to the end and try again. Sudo no longer needs a password.
3.3.The problem 2:secureCRT is stuck / garbled
The secureCRT jam / garbled code here is related to the character set. Pay attention to setting the correct terminal character set and system character set. The default character set of Ubuntu on Windows is Latin.
Sudo vim / etc/default/locale LANG=zh_CN.UTF-8 LANGUAGE= "zh_CN:zh" # # sudo dpkg-reconfigure locales# en_US.UTF-8, zh_CN.GBK, zh_CN.UTF-8##WARNING! Your environment specifies an invalid locale. The unknown environment variables are: LC_CTYPE=zh_CN.UTF-8 LC_MESSAGES=zh_CN.UTF-8 LC_ALL= This can affect your user experience significantly, including the ability to manage packages. You may install the locales by running: sudo apt-get install language-pack-zh or sudo locale-gen zh_CN.UTF-8To see all available language packs, run: apt-cache search "^ language-pack- [a Murz] [a Murz] $" To disable this message for all users, run: sudo touch / var/lib/cloud/instance/locale-check.skip
The other solution does not modify the configuration, but executes the following commands in bash:
Apt-get updateapt-get install language-pack-zh-hansupdate-locale LANG=zh_CN.UTF-8
These commands install Chinese patches and change the local code to Chinese code.
Then restart WSL (close the window, reopen it) and execute the command
Echo $LANG
You can see that the output is
Zh_CN.UTF-8
After that, you can see that the output Chinese in the terminal can be displayed normally.
4. WSL Ubuntu update 4.1 ubuntu system upgrade: (1) version upgrade / / update software source Finally, I will read the package list sudo apt-get update sudo update-manager-c-d and select upgrade:apt-get-y-- force-yes upgrade (2) ordinary upgrade all packages sudo apt-get update sudo apt-get-y upgrade # apt-get-y-- force-yes-- fix-missing upgrade (3) upgrade single software sudo apt-get update sudo apt-get upgrade package_ Name_your_want_to_upgrade apt list-- upgradable-a (4) all upgrades / / updates all software sudo apt-get dist-upgrade (5) upgrade from 16.04to 18.04s Remember afterwards to update / etc/apt/sources.list image source version to boinc apt install update-manager update-manager-core sudo do-release-upgrade-d # autoremove. Be careful to modify Ubuntu image source with sudo apt autoremove4.2:
The domestic access to the Ubuntu update source that comes with WSL is very slow, and it is easy to see that part of the source IP cannot be connected, and then some index files fail to download, resulting in the whole update failure. It is recommended that Aliyun's image is relatively stable and reliable. Of course, you can also refer to the image sources of various universities in China.
(1) the software source configuration file of Ubuntu is / etc/apt/sources.list. First, make a backup of this file that comes with the system: (cd / etc/apt & & sudo cp sources.list sources.list.bak.`date-I`) (2) replace URL in the source file with any domestic source. For example, Aliyun: http://mirrors.aliyun.com/ubuntu deb http://cn.archive.ubuntu.com/ubuntu/ trusty main restricted universe multiverse deb http://cn.archive.ubuntu.com/ubuntu/ trusty-updates main restricted universe multiverse deb http://cn.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse # if you want to use it for other versions, just change the trusty to the version code. For example: 15.10 willy, 14.04 trusty # for more information, please refer to: http://wiki.ubuntu.org.cn/%E6%BA%90%E5%88%97%E8%A1%A8 http://wiki.ubuntu.org.cn/%E6%A8%A1%E6%9D%BF:18.04source (3) sudo apt-get update, refresh the list to make it effective. # Note: be sure to choose the right version # Note: be sure to refresh and reload the configuration
In vim, you can directly:
% s#deb http://archive.ubuntu.com/ubuntu/#deb http://mirrors.aliyun.com/ubuntu/#g%s#deb http://security.ubuntu.com/ubuntu/#deb http://mirrors.aliyun.com/ubuntu/#g
When everything is in place:
5. Use GUI desktop program 5.1 X window system (X Window System) on WSL with the help of X Server
The X window system (X Window System, also often referred to as X11 or X) is a software window system that is displayed as a bitmap. It was first studied by the Massachusetts Institute of Technology in 1984, and later became the operating protocol of standardized software toolkits and display architectures that are consistently applicable to operating systems such as UNIX, UNIX-like, and OpenVMS. The X window system creates a graphical user interface for the operating system through software tools and architecture protocols, and then gradually extends to a variety of other operating systems. Now almost all operating systems can support and use X. More importantly, today's well-known desktop environments, GNOME and KDE, are also based on the X window system.
X Window System is mainly composed of X Server and X Client. X Server is responsible for accepting requests for graphical output (window) and feedback user input, while X Client is an application that uses a graphical interface. Since WSL itself does not support a graphical interface, we need to install additional X Server and specify a graphical output location so that desktop programs with GUI can be displayed and run.
5.2x Server selection
The commonly used X Server on Windows are: Xmanager, Xming, VcXsrv, etc., make a simple comparison:
Xmanager is commercial software and needs to be paid.
Although Xming is open source software, it has been available for download since the last free version in 2007 (6.9.0.31). However, although the free version is old, because X Windows System has not changed much in recent years, the free version is basically enough.
VcXsrv is open source free software, the way of use and interface is very similar to Xming, is still constantly updated, so I finally chose this software
5.3 installation and startup of VcXsrv
After downloading VcXsrv and installing it, run XLaunch and click Next until startup is complete.
5.4 WSL Settin
After starting X Server, you need to enter the following two instructions in WSL to restart Bash to run the Linux program with a graphical interface
Echo export DISPLAY=:0.0 > > ~ / .bashrcsudo sed-I 'sroom.roomtcpmisthostlocalhostgrade.Portal 0$'/ etc/dbus-1/session.conf
Here is a brief explanation of these two instructions:
The first instruction
This instruction adds the export DISPLAY=:0.0 instruction to ~ / .bashrc so that each time a new Bash is opened, the location displayed by the graphics program is automatically specified.
You can also directly enter the following instructions to run the program without export, but the effect is only once. When you run other programs, you have to re-enter the instructions.
DISPLAY=:0.0 gvim & / / gvim for the program you want to open
After tips:gvim & it doesn't have to be added, it means that the program runs in the background so that the command line window can continue to be used while the graphical interface is running. If you forget to add &, you can also press ctrl+z while the program is running, suspend the program process, and type bg to make it run in the background
Second instruction (optional)
The first input, after restarting Bash, you can theoretically run the Linux program, but the program usually does not run long and will die, and will prompt D-Bus exception, which will make many Linux graphics programs can not run well. This is because D-Bus needs to use socket to communicate, but WSL does not currently support socket.
The solution on Reddit is to use tcp instead of sockets to make D-Bus run.
The specific implementation is as follows: in / etc/dbus-1/session.conf (Root permission is required), replace the unix:tmpdir=/tmp field with tcp:host=localhost,port=0, which is simply the second instruction.
5.5 WSL/VcxSrv Chinese garbled
Because there is no support for Chinese fonts in your WSL, you need to install Chinese fonts:
Sudo apt install fonts-noto-cjk or sudo apt install fonts-wqy-microhei fonts-wqy-zenhei xfonts-wqy
If you need to input Chinese in VcxSrv, you can install fcitx Chinese input method. For more information, please see
# getting started with Windows Subsystem for Linux: install + configure graphical interface + Chinese environment + vscode
Https://wu-kan.github.io/posts/linux/Windows-Subsystem-for-Linux
# Building a working environment for windows frontend points to the north
Https://juejin.im/post/5a5f0e3ff265da3e290c3b78
If you have any more questions, you can further set them as follows:
Open xlanch and add startup parameters in the next step.
-fp "C:/Windows/Fonts"
Then restart xming
6. WSL accesses local files
The disks of the local file system are mounted in the / mnt directory. For example, the location of disk C in the subsystem is: / mnt/c. How to configure the read and write permissions of WSL files:
Cat / etc/ wsl.conf.automount] enabled = trueoptions = "metadata,fmask=022,dmask=022,umask=022" options = "metadata" mountFsTab = false6.1 local access to the WSL file
The root location of the Ubuntu subsystem:
[C:UsersusernameAppDataLocalPackagesCanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgscLocalStaterootfs]
Files in the subsystem can be accessed directly when you need to copy them locally, but it is not recommended to manually change the files in the subsystem externally.
What if the subsystem collapses accidentally? There are two ways.
1. Right-click to uninstall, and then reinstall from Microsoft Store.
2. Recommend! Open PowerShell and run ubuntu clean. This command clears all files and configurations from Ubuntu, but does not uninstall the application, which is equivalent to a reset, saving you from reinstalling the application.
Enter ubuntu help to see more instructions.
6.2 Tips sets default login users
The default login account of the subsystem is the normal account that we set up when we initialize. We can change the default account to root.
Open the PowerShell of windows and change the default account to root:
Ubuntu config-default-user root
If you need to change it to another account, just change the root in the command to another user name.
6.3 use of WSL in ConEmu
Follow the figure:
7 、 Docker on WSL
Wsl 2 already fully supports docker, so I won't repeat it in this article, but I'll focus on the wsl version below.
Install Docker in 7.1 WSL
First of all, the WSL command line must be started as an administrator. (use the administrator to open the Ubuntu program, remember that it is not sudo, but the "administrator open" of Windows.)
Sudo apt updatesudo apt install docker.io# sudo groupadd dockersudo usermod-aG docker $USER # grants the current user root privileges to run Docker CLI
If the default installation fails, you can specify the docker version number to install: [WSL+Docker] WSL Ubuntu18 under novice Win10 and install using Docker
Https://zhuanlan.zhihu.com/p/61542198
Then start the WSL console as an administrator and execute
Sudo cgroupfs-mount # A script sudo service docker start for easy loading of control group files
Test the installation results (the following command does not include sudo):
$docker versionClient:. Server: . $docker run-rm hello-world$ docker run-it ubuntu bash
If the above information is displayed, it means it can be used normally. It should be noted that every time the computer is rebooted, execute cgroupfs-mount and then start the docker service. Wsl's current docker support is not perfect, and there may be many problems. It is recommended to use it directly in linux environment, or wsl 2.
7.2 possible questions:
Run docker prompt: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
7.2.1 at this point, you need to connect to docker (client) through deamon. Execute: echo "export DOCKER_HOST=tcp://localhost:2375" > ~ / .bashrc & & source ~ / .bashrc7.2.2 to modify the docker service configuration:
Inside file / lib/systemd/system/docker.service change:
ExecStart=/usr/bin/dockerd fd://
With
ExecStart=/usr/bin/dockerd-H tcp://0.0.0.0:2375
Inside file / etc/init.d/docker change:
DOCKER_OPTS=
With
DOCKER_OPTS= "- H tcp://0.0.0.0:2375"
And then restart your computer (or admin: sudo service docker restart).
7.3 curve to save the nation
If you have the wrong version of Windows/Docker, there will be all kinds of problems. WSL itself may not support / compatible with docker engine. At this time, if we want to run docker (client) in WSL, we need to connect docker client to the docker engine of Windows (which is also the reason why windows docker is installed), and need the following settings.
The above is how to build a cross-platform development environment for Ubuntu on Windows10. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.