so I’m completely new to Ubuntu. I’ve set up a shared folder with a few c programs and when I go to compile in Ubuntu, such as:
gcc file.c -o fileTest
I get the following error:
/usr/bin/ld: cannot open output file fileTest: Permission denied
collect2: error: ld returned 1 exit status
I’m sure that my permissions for the C files are correct, all files have ‘rwx’ permissions.
Do I have to change the permission of the directory as well?
I’m a complete newb, so apologies.
Javier Rivera
34.7k11 gold badges86 silver badges109 bronze badges
asked May 15, 2014 at 21:56
Yes, you have to change the permissions of the directory as well.
This is because if you only have write permissions to the files inside the directory, you can’t just create a new file because you don’t have write permissions for that file (it doesn’t exist, so no permissions to create it).
If you have write permissions for the directory you can create a file inside it because you have write permissions for the directory itself.
To make yourself the owner (terminal way):
-
Check your user name:
whoami
-
Make yourself the owner of the directory and its contents:
sudo chown -R "$USER:" /path/to/the/directory
The
-R
flag stands for recursive, so that directory and all its subfiles and subdirectories will change owner. Remove the-R
flag to just change the permissions of the directory itself.
Now you should be able to create files or directories because you’re now the owner of the directory and all its content. If you still can’t, give the owner write permissions to the directory and its content using the following command:
chmod -R 700 /path/to/the/directory
answered May 15, 2014 at 22:05
0
There is a list of common errors I often see in Ubuntu. There is problem with merge list, then there is BADSIG error, and a number of common Ubuntu update errors.
One of such common errors which I often see while installing a program from its source code is error while loading shared libraries. The full error generally looks like this:
error while loading shared libraries:
cannot open shared object file: No such file or directory
For example, I was trying to use FreeRADIUS server and it showed me this error:
radiusd: error while loading shared libraries:
libfreeradius-radius-2.1.10.so:
cannot open shared object file: No such file or directory
The reason behind this error is that the libraries of the program have been installed in a place where dynamic linker cannot find it.
Let me show you how you can go about fixing this issue.
One quick way to fix this “error while loading shared libraries” automatically is to use ldconfig.
All you need to do is to open terminal (Ctrl+Alt+T) and type the following command:
sudo /sbin/ldconfig -v
This one liner should solve the problem in most cases. However, if it doesn’t, I have discussed another method to handle this error. But before that, let me tell you what does the above command do.
What are shared object files? How does the above command fixes the issue?
You see, in C/C++, a .so (shared object) is a compiled library file. It is called shared object because this library file can be shared by several programs. These generated libraries are usually located in /lib or /usr/lib directories.
Now if you wonder how did this tiny command fixed this problem, you should read the man page of ldconfig which says:
ldconfig creates the necessary links and cache to the most recent shared libraries found in the directories specified on the command line, in the file /etc/ld.so.conf, and in the trusted directories (/lib and /usr/lib). The cache is used by the run-time linker, ld.so or ld-linux.so. ldconfig checks the header and filenames of the libraries it encounters when determining which versions should have their links updated.
I hope this quick fix helps you in eliminating the nasty error while loading shared libraries message in Ubuntu and other Linux.
If not, you can do some investigation and try to fix the issue the way it is mentioned in the next section.
The above discussed method fixes the issue if the library in question is available in your system. But that may not always be the case.
If you do not have the program installed on your system, you won’t have its library file. The ldconfig cannot do anything if there is no library file in the first place.
So, the alternate method is to install the required program and it should create the library automatically.
Let me show it to you by an example. Let’s say you see this error:
error while loading shared libraries: libgobject-2.0.so.0: cannot open shared object file: No such file or directory
The problem is with libgobject version 2.0. The version number is important because some programs depend on a specific version of the library and if they don’t find, they complain about it.
Now, apt provides the search option that can be used for searching a package and knowing its version before installing it.
[email protected]:~$ apt search libgobject
Sorting... Done
Full Text Search... Done
librust-gobject-sys-dev/focal 0.9.0-2 amd64
FFI bindings to libgobject-2.0 - Rust source code
Now, this librust-gobject-sys-dev package could be what you need if you know that you were trying to run a Rust program. But what if it was a Python program you were running that complained about it?
You can widen your search by removing the lib from the package name while searching. The lib signifies library and libraries may be provided by a generic package that could be named gobject-xyz.
It would be a good idea to search for the string in the names of the package (instead of description) to get more concise results.
[email protected]:~$ apt search --names-only gobject
Sorting... Done
Full Text Search... Done
gobject-introspection/focal-updates 1.64.1-1~ubuntu20.04.1 amd64
Generate interface introspection data for GObject libraries
libavahi-gobject-dev/focal 0.7-4ubuntu7 amd64
Development headers for the Avahi GObject library
libavahi-gobject0/focal 0.7-4ubuntu7 amd64
Avahi GObject library
libcairo-gobject-perl/focal,now 1.005-2 amd64 [installed,automatic]
integrate Cairo into the Glib type system in Perl
libcairo-gobject2/focal,now 1.16.0-4ubuntu1 amd64 [installed,automatic]
Cairo 2D vector graphics library (GObject library)
libghc-gi-gobject-dev/focal 2.0.19-1build1 amd64
GObject bindings
libghc-gi-gobject-doc/focal,focal 2.0.19-1build1 all
GObject bindings; documentation
In the above truncated output, you’ll have to see if the package is related to the original program you were trying to run. You must also check the version of the library provided.
Once you have identified the correct package, install it like this:
sudo apt install package_name
Once installed, you may run the ldconfig command again to update the cache:
sudo /sbin/ldconfig -v
This method requires some effort on your end but this is how the dependencies are handled.
Nothing works, what now?
If you are unfortunate enough, the above methods might not work for you. What can you do?
First, keep in mind that the shared libraries may be used from other packages in some cases. If you were trying to run XYZ program and ABC program installs the correct version of the shared library, it may (or may not) work for you. You can give it a hit and trial.
Second, if you are trying to run a program which is too old or too new, it may require a library version which is not available for your Linux distribution.
What you may do is to check if you can use some other version of the program. For example, using Eclipse version 3 instead of version 4. This may help your case.
The other way would be to check the developers website or forums and see if you can manually install the correct version of the library from its source code. That requires a lot of effort (in 2020) but you don’t have a lot of options.
Did it work for you?
I hope I have make things a bit more clear for you. Did you manage to fix the issue of shared libraries in your system? If you have questions, suggestions, feel free to drop a comment. Ciao
Vim can’t open file for writing error is one of the most common and frequent errors you will encounter, if you use Linux and vim editor. Whether you are a novice or Pro Linux user, «E212» is the error code, you don’t like seeing. Most of the time, this error occurs due to insufficient rights or a directory path or file that doesn’t exist, which you are trying to edit. In this post, I will let you know all the reasons and solutions to fix the «Vim can’t open file for writing» error.
When you use Linux, you can get the below-mentioned error, while you try to edit a file —
- /etc/apt/sources.list» E212: Can’t open file for writing
- Vim Can’t Save File (E212)
- Vim can’t open file for writing
- Root user can’t open file for writing
- Error in editing vimrc
- E212: cant open file for writing ec2
Possible causes of the above-mentioned issues —
- You don’t have access or you are trying to edit a file, which is owned by root user
- Path of the file, you are trying to edit doesn’t exist (non existing file, non existing directory)
- Trying to write a network drive and you don’t have access or partial access
- Trying to edit a read only file system
- Not enough space exists in your current partition or drive.
Let’s deep dive and fix errors and it’s causes one by one.
Table of Contents
- 1 Install vim editor in Ubuntu, if not there already
- 2 How to Fix Vim can’t open file for writing error
- 3 How to fix etc/apt/sources.list» E212: Can’t open file for writing
- 4 How to fix even if «Root user can’t open file for writing»
- 5 Video tutorial
- 6 Conclusion
Install vim editor in Ubuntu, if not there already
If you get the error: «Command ‘vim’ not found, but can be installed with:» it means you don’t have vim (visual improved) editor installed. Run the following command to install the package in Ubuntu.
$ sudo apt install vim
Solution-1 Check the directory or path of file, create it if it doesn’t exist
First thing first, if you are getting vim can’t open file for writing error, check the path and directory of the file. Let’s understand it from an example.
I am trying to run a command «vim /home/tmp/sample.txt» and getting this error «/home/tmp/sample.txt» E212: can’t open file for writing» while saving it as shown in the image.
In this scenario, the «tmp» directory inside /home doesn’t exist. So if you will try to either create a new or edit the existing «sample.txt» file. This will not work and you will get errors.
In my case, I need to create the directory tmp inside the /home first to get rid of this "E21: can't open file for writing" error. This may happen in your case also. You may need to create the required directory or maybe you just need to correct the required path :-).
If you want to create a directory without closing the vim editor prompt because you have already edited the file and you don’t want to lose changes. Then follow these steps-
- Press «ESC» on your keyboard.
- Type «!sudo mkdir «path of directory that need to be created«. For example, in my case i need to create «tmp» directory inside /home.
E.g.
:!sudo mkdir /home/tmp/
As soon as you will run this command and press enter, It may ask you to give your sudo credentials, and your required directory will get created as shown in the image.
You can edit, save and exit your file now with the «:wq» command without any issue.
How to get the reason of error «E21: can’t open file for writing» using vim help
To find out the reason for the error, follow these steps in the vim editor prompt, where you are getting an error.
- Press «esc» key on your keyboard
- Then type :h e212 as shown in image «:h -« represents help and e212 error. Same way you can check for any error, you encountered in vim editor
- Press enter and you will get the error code and its reason. For example, in my case it is showing the follow —
For some reason the file you are writing to cannot be created or overwritten. The reason could be that you do not have permission to write in the directory or the file name is not valid.
Press the «ESC» key and then type «:q!» to exit from help.
How to fix etc/apt/sources.list» E212: Can’t open file for writing
If you use Linux, many times in your lifetime. You would have edited the sources.list file and I am sure, you would have encountered an E212 error. Follow solution-2 step by step to fix this issue.
Solution-2 Validate User or file permissions
If you are trying to edit a file and you have given the correct path but still you are getting «can’t open file for writing error«, then you are a victim of permission issues.
If you are logged in with a non-root user, make sure you start with the sudo command, if you are trying to edit a system file or file owned by root.
Let me show you an example, try editing /etc/apt/sources.list with a non-root user and you will understand, what I am trying to prove here.
If you will see the below image, the «sources.list» file is owned by root, so if you will try to edit it using a non-root-user with the following command
$ vim /etc/apt/sources.list
You will get «/etc/apt/sources.list» E212: Can’t open file for writing» error.
To fix it, you must edit this file using sudo permissions. run the following command to edit this file successfully.
$ sudo vim /etc/apt/sources.list
How to fix even if «Root user can’t open file for writing»
If you are a root or sudo user, Also you have given the correct path to directory or file but still, you are not able to open the file for writing. Then you are trying to edit a read-only file system or your disk space is full, which doesn’t allow editing and saving a file.
Solution3- Check for Read-only file system or Capacity issue
Use the «df» command to check the partition or disk space usage. If you see «disk» or «partition» available space is showing «0» bytes except for «/dev/loop».
Then make space by deleting or removing unnecessary files using the rm command. It will fix your «vim can’t open file for writing» issue.
$ df -h
If you have enough space, then make sure your file system is not mounted as read-only. Run the «mount» command and check for your device, it must be mounted as read-write (rw) not read-only (ro).
For example, /dev/sda5, which is my root (/) partition, mounted as rw.
$ mount
If it is showing mounted as read-only in your case, then remount it as rw. If it’s happening due to file system errors, then fix the file system errors and re-mount it to a read-write file system.
$ sudo mount -o remount,rw /partition/identifier /mount/point or $ sudo mount -o remount,rw /
You will be able to edit your file, once your file system will be rw and your «vim can’t open file for writing» will vanish.
Video tutorial
Conclusion
I am hopeful, that one of the 3 solutions shared in this post will fix your «E212: Vim can’t open file for writing» error. If you are still facing issues, You can let me know, via your comments. I will try to help you to the best of my knowledge.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Linux open failed: No such file or directory error
Hi, The below commands works fine on serverB
. /etc/profile;
cd /export/home/user2/utils/plugin/
./runme.shHowever, when i run the same commands from serverA it fails
$ ssh -q user2@serverB «. /etc/profile; cd /export/home/user2/utils/plugin; ./runme.sh»Output Error:
Please find the below… (8 Replies)
Discussion started by: mohtashims
2. Shell Programming and Scripting
awk can’t open file; file merge attempt
Dear all, I have an AWK related issue.
I have two data files; the first, FileA has fewer lines, the second, FileB has more. FileA is a subset of FileB . Both files are tab delimited.
What I want to do?
When the first two columns for FileA match the first two columns of FileB, I want to… (4 Replies)
Discussion started by: A_Human_Person
3. Linux
Cannot open shared object file: No such file or directory
Hi,
While running tcpdump command on my Fedora 16 machine I am get shared library issue.
# tcpdump
tcpdump: error while loading shared libraries: libcrypto.so.6: cannot open shared object file: No such file or directory
# which tcpdump
/usr/software/sbin/tcpdump
I have tried… (3 Replies)
Discussion started by: muzaffar.k
4. Solaris
./curl -V showing fatal: libldap.so.5: open failed: No such file or directory
Hi Guys,
I am facing this Error
bash-2.03$ ./curl -V
ld.so.1: curl: fatal: libldap.so.5: open failed: No such file or directory
Killed
bash-2.03$
while executing
./curl -V in /opt/sfw/bin directory.
I am using Sun Solaris 10.
which package upgrage can give me this missing… (9 Replies)
Discussion started by: manalisharmabe
5. Shell Programming and Scripting
Cannot open [No such file or directory]
I am seeking help on one script that I created to celan up database audit files. The error returned is
$./clean_audit.sh: /opt/oracle/logs/audit_clean.log: cannot open The same script is working on other 2 or 3 servers. But not working on other 4 servers. All servers are Oracle Linux. Here is… (21 Replies)
Discussion started by: duke0001
6. Shell Programming and Scripting
fatal: cannot open file `TNAME’ for reading (No such file or directory)
Hi,
I am running this command through a shell script and getting the error mentioned in the subject line:
testing.awk -f x.txt TNAME
My testing.awk file contains something like
++++++++++++++++++
#!/usr/bin/awk -f
BEGIN{
TAB_NAME=»INSERT_ONE_» ARGV ;
}
if ( $1==»JAM_ONE» &&… (1 Reply)
Discussion started by: kunwar
7. Red Hat
libodbc.so.1: cannot open shared object file: No such file or directory
We are trying to install third party software on this unix server…
Here is the error message we are getting…
error while loading shared libraries: libodbc.so.1: cannot open shared object file: No such file or directory
It seems like odbc driver is not installed…
>rpm -q unixODBC… (1 Reply)
Discussion started by: govindts
9. Solaris
Error- ld.so.1: expr: fatal: libgmp.so.3: open failed:No such file or directory
Hi Friends
I have a compiler(Sun Forte,I believe) running in my Solaris 9 box.
since y’day my development team is finding this error when they compile:
ld.so.1: expr: fatal: libgmp.so.3: open failed: No such file or directory
I ran a search for this file and found it in one of my file… (2 Replies)
Discussion started by: Hari_Ganesh
10. Programming
libRmath.so: cannot open shared object file: No such file or directory
% locate Rmath
/m/backup/backup/lib/R/include/Rmath.h
/usr/lib/R/include/Rmath.h
% gcc -g -o stand stand.c -I/usr/lib/R/include/ -lRmath -lm
% ./stand
./stand: error while loading shared libraries: libRmath.so: cannot open shared object file: No such file or directory
What’s the trouble… (6 Replies)